springboot profiles
Spring Profile 提供隔離部分配置的方法 并使它們僅僅在某些環境生效。通過@Component或@Configuration 配合 @Profile來實現。
@Configuration @Profile("production") public class ProductionConfiguration {// ... }通常,你是通過設置環境中的spring.profiles.active屬性來指定那些profiles生效。比如在application.properties中設置
spring.profiles.active=dev,hsqldb或通過命令行設置等。
1、添加active profile
當多個命令同時設置spring.profiles.active屬性值的時候,高權限的命令會獲勝,也就是說,application.properties中對spring.profiles.active的設置會覆蓋默認的,而命令行的會覆蓋application.properties中的。
但通常對于profiles不是替換他們而是添加他們,spring.profiles.include屬性作用就是添加profiles。SpringApplication同時提供了方法添加profiles,詳情見setAdditionalProfiles()方法。
2、程序設定profiles
在項目啟動之前執行SpringApplication.setAdditionalProfiles(…?),也可以通過ConfigurableEnvironment接口激活profiles。
3、Profiles配置文件
配置文件application.properties(或application.yml)和參照了@ConfigurationProperties注解的文件都被加載。(后面會詳細介紹)
轉載于:https://www.cnblogs.com/qins/p/7532495.html
總結
以上是生活随笔為你收集整理的springboot profiles的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 重构改善既有代码设计--重构手法11:M
- 下一篇: 第一个项目GeoQuiz开发总结