【发布时间】: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();
【问题讨论】: