[英]Spring Boot - Where to put properties files when deploying to Tomcat?
I've been using Spring Boot
for a few weeks already, and I'm used to work with the application.properties
file. 我已经使用
Spring Boot
几周了,而且我习惯使用application.properties
文件。 I'm able to use it for simple deployment and use with java jar
or mvn spring-boot:run
. 我可以使用它进行简单的部署,并与
java jar
或mvn spring-boot:run
。
Now I'm trying to deploy my application to a Tomcat 8.0.15
application server. 现在我正在尝试将我的应用程序部署到
Tomcat 8.0.15
应用程序服务器。 I've been reading of documentation, but I can't deploy the war
file because Tomcat can't find this famous application.properties
file. 我一直在阅读文档,但我无法部署
war
文件,因为Tomcat无法找到这个着名的application.properties
文件。 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? 我的观点是,如果我想把这个文件排除在
war
,那么在我的Tomcat安装中我应该把它自动读取?
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 如果您以后不想更改它,只需将它放在类路径的根目录中,例如,如果它是Maven项目,那么在里面
<project-folder>/src/main/java/
If you want to change it later without rebuilding WAR then in Tomcat properties file 如果您想稍后更改它而不重建WAR,那么在Tomcat属性文件中
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. 顺便说一句,我现在会选择使用基于注释的配置,但话说再说一次,如果没有重建WAR,它就没有变化的舒适感。
Spring loads the properties from Spring加载属性
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 请参阅docs(23.2应用程序属性文件): 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. 您可以在catalina.sh/catalina.batch或setEnv.bat / setEnv.sh中提供属性文件的位置作为“JAVA_OPTS”的一部分。 set JAVA_OPTS=-Dspring.config.location=file:/D:/Appconfig/application.properties
设置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. 仅供参考:如果外部战争并且如上所述定义,则application.yaml将不会被spring boot加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.