3

Is there a way to create an ApplicationContext (or whatever else in Spring you can use to do getBean("beanName") ) by passing in an XML file that is in memory? The only methods I've been able to find involve providing a file or directory.

1 Answer 1

4

You could give it a try:

import org.springframework.context.support.GenericXmlApplicationContext;

String xmlDef = "...";
ApplicationContext ctx = new GenericXmlApplicationContext(new InputStreamResource(new ByteArrayInputStream(xmlDef.getBytes("UTF-8"))))
Sign up to request clarification or add additional context in comments.

1 Comment

This got me to the actual solution, thanks! new GenericXmlApplicationContext(new ByteArrayResource(xmlDef.getBytes("UTF-8")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.