1.profile
在生產(chǎn)中我們通常會(huì)使用maven的-P來指定環(huán)境選項(xiàng)。
在Spring中也有類似的功能實(shí)現(xiàn)環(huán)境隔離。
相關(guān)注解是:
> @Profile("xxx") 可以在類或者方法上使用,表明該配置類或者方法需要在xxx環(huán)境下激活。
> @ActiveProfiles 測(cè)試環(huán)境指定環(huán)境變量時(shí)使用。
激活profile環(huán)境的參數(shù)可以配置在以下位置:
兩種配置變量:
1.spring.profiles.active
2.spring.profiles.default
配置位置:
1. DispatcherServlet的初始化參數(shù)
2. web上下文參數(shù)
3. JNDI條目
4. 環(huán)境變量
5. JVM系統(tǒng)屬性
6. 使用ActiveProfiles注解
2.bean的作用域
- 單例模式
- 原型Prototype
- 回話
- 請(qǐng)求