diff --git a/IX. ‘How-to’ guides/63.5. Set the active Spring profiles.md b/IX. ‘How-to’ guides/63.5. Set the active Spring profiles.md index e69de29..62e7dcb 100644 --- a/IX. ‘How-to’ guides/63.5. Set the active Spring profiles.md +++ b/IX. ‘How-to’ guides/63.5. Set the active Spring profiles.md @@ -0,0 +1,13 @@ +### 63.5. 设置生效的Spring profiles + +Spring `Environment`有一个API可以设置生效的profiles,但通常你会设置一个系统profile(`spring.profiles.active`)或一个OS环境变量(`SPRING_PROFILES_ACTIVE`)。比如,使用一个`-D`参数启动应用程序(记着把它放到main类或jar文件之前): +```shell +$ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar +``` +在Spring Boot中,你也可以在application.properties里设置生效的profile,例如: +```java +spring.profiles.active=production +``` +通过这种方式设置的值会被系统属性或环境变量替换,但不会被`SpringApplicationBuilder.profiles()`方法替换。因此,后面的Java API可用来在不改变默认设置的情况下增加profiles。 + +想要获取更多信息可查看'Spring Boot特性'章节的[Chapter 24, Profiles](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-profiles)。