springmvc之Profile

Spring为我们提供的可以根据当前环境,动态的**和切换一系列组件的功能。

@Profile(“test”):指定生效环境。默认是default环境。

切换环境方式:

1、通过命令行**

springmvc之Profile

springmvc之Profile

 

2、通过代码方式**
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfig.class);
applicationContext.getEnvironment().setActiveProfiles("test", "dev");
        applicationContext.register(SpringConfig.class);
applicationContext.refresh();

 

更多问题可以加公众号:代码小栈,期待为您解决更多问题

springmvc之Profile