问题描述
此刻,我的所有属性都在文件src/main/resources/application.properties
中定义.但是,我想在src/main/resources/config
文件夹中拥有与不同配置文件相关的属性文件,并且我希望能够选择其中任何一个.例如:
At the moment, all my properties are defined in the file 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. such as:
-
application-DEV.properties
-
application-TEST.properties
-
application-SERVER1.properties
application-DEV.properties
application-TEST.properties
application-SERVER1.properties
因此,问题是如何选择这些属性.如果要编译为jar
文件,则可以通过在运行jar
文件时指定配置文件来轻松地做到这一点,但是在这里,我只是将生成的war
文件复制到Tomcat webapps目录中.
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.
推荐答案
好吧,我找到了一种方法.在Tomcat的conf
目录中,将此行添加到文件catalina.properties
中.
Well, I've found a way to do that. In the conf
directory of Tomcat, add this line to the file catalina.properties
there.
spring.profiles.active=<YOUR_PROFILE>
在此处用您的个人资料名称替换<YOUR_PROFILE>
.例如,如果您使用的是application-TEST.properties
,它将是以下内容.
Replace <YOUR_PROFILE>
here of course with your profile's name. For example if you are using application-TEST.properties
, it would be the following.
spring.profiles.active=TEST
这篇关于将Spring Boot War文件部署到Tomcat时如何指定配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!