关闭或停止后重新加载弹簧上下文

Posted

技术标签:

【中文标题】关闭或停止后重新加载弹簧上下文【英文标题】:Reloading spring context after close or stop 【发布时间】:2018-08-10 11:13:57 【问题描述】:

如何使用不同的系统变量集重新加载 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();

【问题讨论】:

***.com/questions/24720330/… 【参考方案1】:
context.refresh()

正在工作。

【讨论】:

以上是关于关闭或停止后重新加载弹簧上下文的主要内容,如果未能解决你的问题,请参考以下文章