[英]How to set default environment in Spring Boot
How can I set the default environment in Spring Boot? 如何在Spring Boot中设置默认环境?
I put in application.properties
: 我放入
application.properties
:
spring.profiles.include=prod,dev
spring.profiles.active=prod
and in user variables: 在用户变量中:
SPRING_PROFILES_ACTIVE = dev
So when I dev in my comp my environment are dev but when I generate my .war
and deploy in tomcat he still using dev
with enviroment (I deploy in another comp with no other conf) 因此,当我开发我的环境时,我的环境是dev,但是当我生成我的
.war
并在tomcat中部署时,他仍然使用dev
环境(我在另一个comp中部署而没有其他conf)
How can I set my default environment (if he don't find any in user variables or commmand line uses production)? 如何设置我的默认环境(如果他在用户变量或命令行中没有找到任何产品)?
Take a look at the Spring Boot guide on profile specific properties 查看配置文件特定属性的Spring Boot指南
http://docs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-profile-specific-properties http://docs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-profile-specific-properties
I would remove what you have from your application.properties. 我会从你的application.properties中删除你拥有的东西。 You are telling it to include (not replace) both dev and prod profiles.
您告诉它包括(而不是替换)dev和prod配置文件。 A much easier setup is to have
更简单的设置就是拥有
What you need is: 你需要的是:
1) Define the active profile you need, something like: 1)定义您需要的活动配置文件,例如:
spring.profiles.active=dev
In this example the loaded file will be application-dev.properties
在此示例中,加载的文件将是
application-dev.properties
Now, if you need to switch to a different environment depending where are you installing your war file what you can do is to set this variable as a system variable in each environment you want, that way each environment has a different value for the same key, something like: 现在,如果您需要切换到不同的环境,具体取决于您在哪里安装war文件,您可以做的是将此变量设置为您想要的每个环境中的系统变量,这样每个环境对于同一个键具有不同的值, 就像是:
-Dspring.profiles.active=dev
In my case I am using Tomcat and I declare this key/value in the file setenv.sh
, you need to assign that value depending on the server you're using. 在我的情况下,我使用Tomcat并在
setenv.sh
文件中声明此键/值,您需要根据您使用的服务器分配该值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.