Description
Currently, the ConverterManager loads beans from the converter.xml file, but there is an issue when these beans depend on other beans that are instantiated by annotations in the main ApplicationContext. To address this, we are using ApplicationContextAware to save the main application context and let the beans instantiate their dependencies at runtime. However, this approach is not straightforward and introduces unnecessary complexity.
A more elegant and maintainable solution would be to use a parent-child relationship between the main application context and the converter.xml beans. By creating a separate GenericApplicationContext and setting the main context as its parent, we can ensure that the beans from converter.xml can properly access and inject the necessary dependencies from the main ApplicationContext.
The implementation could look like this:
`
GenericApplicationContext xmlContext = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xmlContext);
reader.loadBeanDefinitions(new FileSystemResource(converterXmlApplicationContextPath));
xmlContext.setParent(applicationContext); // This is the main Spring context
xmlContext.refresh();
`