1. 程式人生 > >spring profile

spring profile

初始 conf dispatch web 配置 系統 files 優先 default

配置,激活profile. 處理測試環境,開發環境,生成環境的不同配置.

Javaeconfig配置Profile

@Profile註解指定某個bean屬於哪一個profile

xml配置Profile

技術分享

可以在根<beans>元素中嵌套定義<beans>元素,而不是為每個環境都創建一個profileXML文件。這能夠將所有的profile bean定義放到同一個XML文件中

技術分享

激活profile

Spring在確定哪個profile處於激活狀態時,需要依賴兩個獨立的屬性:spring.profiles.active和spring.profiles.default。如果設置了spring.profiles.active屬性的話,

那麽它的值就會用來確定哪個profile是激活的。但如果沒有設置spring.profiles.active屬性的話,那Spring將會查找spring.profiles.default的值。如果spring.profiles.active

spring.profiles.default均沒有設置的話,那就沒有激活的profile,因此只會創建那些沒有定義在profile中的bean.

系統會優先使用spring.profiles.active中所設置的profile

有多種方式來設置這兩個屬性:
作為DispatcherServlet的初始化參數;
作為Web應用的上下文參數;
作為JNDI條目;


作為環境變量;
作為JVM的系統屬性;
在集成測試類上,[email protected]

技術分享

技術分享

spring profile