I've been using Spring Boot
for a few weeks already, and I'm used to work with the application.properties
file. I'm able to use it for simple deployment and use with java jar
or mvn spring-boot:run
.
Now I'm trying to deploy my application to a Tomcat 8.0.15
application server. I've been reading of documentation, but I can't deploy the war
file because Tomcat can't find this famous application.properties
file. My point is, if I want to put this file out of the war
, where in my Tomcat installation should I put it for it to be automatically read?
If you don't want to change it later, just put it in the root of your classpath, eg if it's Maven project then inside
<project-folder>/src/main/java/
If you want to change it later without rebuilding WAR then in Tomcat properties file
catalina.properties
there is
shared.loader=
that makes properties files listed after equals sign accessible to deployed applications. Better use absolute paths.
BTW, I would opt to use annotation-based configuration nowadays, but then again, it doesn't have the comfort of changing without rebuilding WAR.
Spring loads the properties from
1) A /config subdir of the current directory.
2) The current directory
3) A classpath /config package
4) The classpath root
See the docs(23.2 Application property files): http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-application-property-files
This should work the same way for war(The classpath root one looks the best for me) .
You can provide the location of properties file as part of "JAVA_OPTS" in catalina.sh/catalina.batch or setEnv.bat/setEnv.sh. set JAVA_OPTS=-Dspring.config.location=file:/D:/Appconfig/application.properties
Just for info:application.yaml will not be loaded by spring boot if outside war and defined like above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.