[英]How to specify a profile when deploying a Spring boot war file to Tomcat?
At the moment, all my properties are defined in the file src/main/resources/application.properties
. 目前,我的所有属性都在文件
src/main/resources/application.properties
。 However, I would like to have properties files relating to different profiles in the src/main/resources/config
folder, and I want to be able to choose any of them. 但是,我想在
src/main/resources/config
文件夹中有与不同配置文件相关的属性文件,我希望能够选择其中任何一个。 such as: 如:
application-DEV.properties
application-TEST.properties
application-SERVER1.properties
So, the question is how to select these properties. 所以,问题是如何选择这些属性。 If I was compiling to a
jar
file, I could do that easily by specifiying the profile when running the jar
file, but here I just copy the generated war
file to a Tomcat webapps directory. 如果我正在编译一个
jar
文件,我可以通过在运行jar
文件时指定配置文件轻松地做到这一点,但在这里我只是将生成的war
文件复制到Tomcat webapps目录。
Well, I've found a way to do that. 好吧,我找到了办法。 In the
conf
directory of Tomcat, add this line to the file catalina.properties
there. 在Tomcat的
conf
目录中,将此行添加到catalina.properties
文件中。
spring.profiles.active=<YOUR_PROFILE>
Replace <YOUR_PROFILE>
here of course with your profile's name. 当然,将
<YOUR_PROFILE>
替换为您的个人资料名称。 For example if you are using application-TEST.properties
, it would be the following. 例如,如果您使用的是
application-TEST.properties
,则它将如下所示。
spring.profiles.active=TEST
您可以根据您的环境在服务器启动文件(.bat / .sh)上定义-Dspring.profiles.active=<PROFILE>
Argument -Dspring.profiles.active=<PROFILE>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.