Programmatically add XML property source to current environment in Spring -
i'm trying import xml config programmatically current environment in spring application. here code:
@springbootapplication public class application { public static void main(string[] args) { configurableapplicationcontext app = springapplication.run(application.class, args); try { app.getenvironment().getpropertysources().addlast(new resourcepropertysource("classpath:conf.xml")); } catch (ioexception e) { system.out.println("there error" + e.getmessage()); } catch (exception e) { system.out.println("there error" + e.getmessage()); } } }
here's conf.xml
:
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="org.springframework.context.support.propertysourcesplaceholderconfigurer"> <property name="locations"> <list> <value>classpath:defaults.properties</value> </list> </property> <property name="ignoreunresolvableplaceholders" value="true"/> </bean>
i have defaults.properties
file in classpath.
when run application, hits ioexception catch block error:
there errororg.xml.sax.saxparseexception; linenumber: 5; columnnumber: 115; document root element "beans", must match doctype root "null".
things i've tried:
- specifying root element "beans" in
<!doctype>
declaration. got error saying "beans" element wasn't defined - checked spring framework version. spring 4.3.x. afaik doctype-style/dtd xml has been superseded schema xml after spring 2 (forgive me if i'm using wrong terminology these things)
- tried other similarly-structured xml files
does know error is?
i've forked 1 of spring guides show problem also. code samples taken there: https://github.com/jogjayr/gs-rest-service/tree/master/complete
Comments
Post a Comment