Reputation: 415
I have the following spring-boot 1.4.2.RELEASE sample app
@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 run it 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 fails to inject 'spring.application.name'? Need to define it there to support other spring boot cloud.
Upvotes: 15
Views: 28528
Reputation: 111
The first answer is correct. The default properties file is application.properties or application.yml.
The bootstrap file is properly for Spring Cloud.
See http://projects.spring.io/spring-cloud/spring-cloud.html#_the_bootstrap_application_context
If you are using spring cloud, and the bootstrap file is not working, you need to enable the "cloud" Spring profile.
For example using:
./gradlew -Dspring.profiles.active=cloud bootrun
or
./mvnw spring-boot:run -Dspring.profiles.active=cloud
Upvotes: 8
Reputation: 566
By default, if you don't specify any properties source, spring boot will lookup for your property in the file application.properties
. Therefore, you should rename your property file to that default name or manually specify a properties source for your bootstrap.properties
Upvotes: 6