I\'m fairly new to spring/java and have been checking out spring-boot for a project I have at work. I\'ve been following guides and finally have a (semi) working web app MVC
I think for those who change default naming "application.[properties,yaml,etc]" to, for example, "service.[properties,yaml,etc]", can add this into the build.gradle task as:
bootRun {
systemProperties = [
'spring.config.name':'service'
]
}
I came here searching for the same issue. application.properties not loading when spring boot application run as a war inside tomcat but it was working fine when running with embedded tomcat. the issue turned out to be in the file name . I had used Application.properties instead of application.properties . when running from tomcat it looks like it is case sensitive . Putting it here so that if someone commits the same stupid mistake as i did
2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./config/application.xml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./config/application.yml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./config/application.properties' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./config/application.yaml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./application.xml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./application.yml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./application.properties' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'file:./application.yaml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/config/application.xml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/config/application.yml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/config/application.properties' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/config/application.yaml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/application.xml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/application.yml' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/application.properties' resource not found 2015-09-10 14:42:13,982 DEBUG o.s.b.c.c.ConfigFileApplicationListener [ContainerBackgroundProcessor[StandardEngine[Catalina]]] Skipped config file 'classpath:/application.yaml' resource not found
follow this guys advice: http://blog.codeleak.pl/2013/11/how-to-propertysource-annotations-in.html
try:
@PropertySources(value = {@PropertySource("classpath:application.properties")})
then boom sauce for the win.
The problem is that you attempt to use a @Value
annotation inside your @Configuration
class. From the JavaDoc of the @PropertySource:
In order to resolve ${...} placeholders in <bean> definitions or @Value annotations using properties from a PropertySource, one must register a PropertySourcesPlaceholderConfigurer. This happens automatically when using <context:property-placeholder> in XML, but must be explicitly registered using a static @Bean method when using @Configuration classes.
e.g. add the following lines to the @Configuration
class:
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
However, in your example, a more suitable approach is to move the @Configuration
annotation from the GreetingController
class (it does not contain any configuration) to the Application
class. Since the Application
class does not contain any @Value
annotation it should work without the suggested addition of the static PropertySourcesPlaceholderConfigurer
bean.