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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-14
  • 2022-01-22
  • 2022-02-17
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-09-28
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
相关资源
相似解决方案