首页 > 解决方案 > 关闭或停止后重新加载弹簧上下文

问题描述

如何使用不同的系统变量集重新加载 spring 上下文。在下面的场景中,我正在寻找加载 dev1 属性,在使用 dev2 属性重新启动上下文之前初始化 bean。我想聚合具有不同系统变量的初始化 bean 的响应。

System.setProperty("env","dev1");
String configFile = "spring/app_context.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configFile);
context.start();
context.close();

System.setProperty("env","dev2");
String configFile = "spring/app_context.xml";
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configFile);
context.start();

标签: javaspring

解决方案


context.refresh()

正在工作中 。


推荐阅读