日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

springboot profiles

發布時間:2025/4/16 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。