Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Spring ApplicationContext from in memory XML

Tags:

java

spring

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.

like image 416
Malcolm O'Hare Avatar asked Nov 29 '25 21:11

Malcolm O'Hare


1 Answers

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"))))
like image 192
Xeon Avatar answered Dec 02 '25 12:12

Xeon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!