How to update all spring objects after setting up a new configuration?

How to update earlier @Autowiredspring objects after dynamic configuration changes?

// 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);

With myApplicationContextAware.applicationContext.getBean(MyClass.class)I can get new instances using the new configuration, but all objects @Autowiredstill contain old values

Is there any solution for updating spring objects?

+4
source share
1 answer

You can use AbstractRefreshableApplicationContext for this. It provides methods for reloading the bean configuration at runtime.

spring, @RefreshScope spring . spring /refresh beans, @RefreshScope.

+2

All Articles