1、在Java中配置profile bean
使用@Profile("xxx")注解,既可以在配置类级别使用,也可以在方法级别使用,指定profile的bean会在相应profile激活的情况下创建,未指定的始终会被创建。
2、在XML中配置profile bean
既可以在根<beans>中通过profile="xxxx"进行配置,也可以在根<beans>中嵌套定义<beans>元素进行配置。
3、激活profile
设置spring.profiles.active和spring.profiles.default的多种方式:
- 作为DispatcherServlet的初始化参数
- 作为Web应用的上下文参数
- 作为JNDI条目
- 作为环境变量
- 作为JVM的系统属性
- 在集成测试类上,使用@ActiveProfiles注解设置
可以同时激活多个profile。