spring_reference/IX. ‘How-to’ guides/63.5. Set the active Spring...

14 lines
988 B
Markdown
Raw Normal View History

### 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)。