As the title says, I want to load some beans from a String.
This approach only works in Spring 3 because GenericXmlApplicationContext
is unavailable in version 2.5.
Asked
Active
Viewed 708 times
0

Community
- 1
- 1

Pantaziu Cristian
- 882
- 2
- 14
- 26
2 Answers
0
I have not tested it myself, but according to the API documentation, you can easily extend the AbstractXmlApplicationContext and implement the getConfigResources()
method.
You can use the org.springframework.core.io.ByteArrayResource
to serve as a placeholder for your XML string.

jeroen_de_schutter
- 1,843
- 1
- 18
- 21
0
Use the approach outlined here. With one additional step, pass the DefaultListableBeanFactory
into a GenericApplicationContext
(this one has been around since Spring 1.1 and the GenericXmlApplicationContext is basically a convenience class doing more or less the same as in that blog post).
So something like this should work
String content = ...
GenericApplicationContext ctx = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
reader.loadBeanDefinitions(new ByteArrayResource(content.getBytes()));
ctx.refresh();
The ApplicationContext
should now be ready for use.

M. Deinum
- 115,695
- 22
- 220
- 224