企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 69.6 设置生效的Spring profiles ### 69.6 设置生效的Spring profiles Spring `Environment`有一个API可以设置生效的profiles,但通常你会通过系统属性(`spring.profiles.active`)或OS环境变量(`SPRING_PROFILES_ACTIVE`)设置。比如,使用一个`-D`参数启动应用程序(记着把它放到`main`类或jar文件之前): ``` $ java -jar -Dspring.profiles.active=production demo-0.0.1-SNAPSHOT.jar ``` 在Spring Boot中,你也可以在`application.properties`里设置生效的profile,例如: ``` spring.profiles.active=production ``` 通过这种方式设置的值会被系统属性或环境变量替换,但不会被`SpringApplicationBuilder.profiles()`方法替换。因此,后面的Java API可用来在不改变默认设置的情况下增加profiles。 想要获取更多信息可查看'Spring Boot特性'章节的[Chapter 25, Profiles](../IV.%20Spring%20Boot%20features/25.%20Profiles.md)。