[Solved] How can I register beans from Spring XML file at runtime?


Thanks to comment of cheffe where he links to another question/answer, I’ve came to the following solution:

@Autowired
GenericApplicationContext context;

private void loadBeans(String beansXml) {
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context);
    xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
    xmlReader.loadBeanDefinitions(new InputSource(new StringReader(beansXml)));
}

The problem seems to be the creation of the new GenericApplicationContext. It looks like the beans are only in this context but not known in the existing context.

1

solved How can I register beans from Spring XML file at runtime?