2

I'm trying to convert a traditional Tomcat Spring MVC webapp to Spring Boot. The new application should still use .war deployment.

For various reasons I have the obligatory requirement that the application.properties file resides inside a WEB-INF/conf folder in the deployed app and NOT inside the WEB-INF/classes folder where Spring Boot puts it by default.

In the original webapp I could put the application.properties file inside the src/main/webapp/WEB-INF/conf folder (so they get copied to WEB-INF/conf in the deployed application) and then use it like this:

<context:property-placeholder location="/WEB-INF/conf/application.properties"/>

What is the Spring Boot way to refer to this location?

I tried adding each of the following:

spring.config.location=WEB-INF/conf/application.properties

but my application.properties file still doesn't get loaded.

Bragolgirith
  • 2,167
  • 2
  • 24
  • 44
  • remove the `webapp` part... The file is still at the same location. But still if it is part of the war why should the location matter? – M. Deinum Jun 02 '16 at 13:20

1 Answers1

0

What finally worked was the following @PropertySource annotation.

@SpringBootApplication
@PropertySource(value = {"WEB-INF/conf/application.properties"})
public class MyApplication {
        public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}

It seems that not specifying classpath: or file: at the beginning of a path makes it use a path relative to the webapp.

I'm still not sure as to why specifying

spring.config.location=WEB-INF/conf/application.properties

didn't have the same effect.

Bragolgirith
  • 2,167
  • 2
  • 24
  • 44