How can I access spring.application.name 'if it is defined in bootstrap.properties?

I have the following spring-boot 1.4.2.RELEASE sample application

@SpringBootApplication public class Application { @Value("${spring.application.name}") private String applicationName; public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 

And I have the following configuration defined in bootstrap.properties:

 spring.application.name=sample-app 

When I start, I get the following error:

 java.lang.IllegalArgumentException: Could not resolve placeholder 'spring.application.name' in string value "${spring.application.name}" 

Any hint on why it is not able to insert 'spring.application.name'? You need to define it there to support another spring boot cloud.

+5
source share
2 answers

The first answer is correct. The default properties file is application.properties or application.yml.

The boot file is correct for Spring Cloud.

See http://projects.spring.io/spring-cloud/spring-cloud.html#_the_bootstrap_application_context

If you use the Spring cloud and the bootstrap file does not work, you need to enable the Spring cloud profile.

For example, using:

 ./gradlew -Dspring.profiles.active=cloud bootrun 

or

 ./mvnw spring-boot:run -Dspring.profiles.active=cloud 
+2
source

By default, if you do not specify the source of any properties, spring boot will look for your property in the application.properties file. Therefore, you must rename your properties file to this default name or manually specify the source of the properties for your bootstrap.properties

+2
source

Source: https://habr.com/ru/post/1261303/


All Articles