【发布时间】:2016-04-08 13:57:06
【问题描述】:
动态配置更改后如何刷新之前的@Autowiredspring 对象?
// Here is my updateConfig method
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
context.refresh();
myApplicationContextAware.setApplicationContext(context);
使用myApplicationContextAware.applicationContext.getBean(MyClass.class) 我可以通过新配置获取新实例,但所有@Autowired 对象仍然包含旧值
有没有办法刷新spring对象?
【问题讨论】:
标签: java spring dependency-injection configuration autowired