java - Referencing xsds on classpath when using Spring beans to call xsl -



java - Referencing xsds on classpath when using Spring beans to call xsl -

so working on project uses spring inject schema location xsd when calling xsl, like:

<bean id="transformer" class="com.mypackage.transformer"> <property name="xsl" value="sample.xsl" /> <property name="params"> <map> <entry key="schemalocation" value-ref="schema" /> </map> </property> </bean> <bean id="schema" class="java.lang.string"> <constructor-arg value="http://www.sample.com/schema/sampleschema.xsd" /> </bean>

this works fine when utilize url schema location, illustration want refer schema brought in on classpath maven dependency. i've found using 'classpath:sampleschema.xsd' doesn't work. would've thought kind of behaviour common, there accepted workaround this? create custom class looks schema on classpath , returns path string?

ok thought share how fixed this.

two spring beans:

<bean id="schema" factory-method="getschemalocation" factory-bean="schemafinder" /> <bean id="schemafinder" class="com.mypackage.schemafinder"> <constructor-arg value="name_of_schema" /> </bean>

and class:

public class schemafinder { private string schemalocation; public schemafinder(string schemaname) throws exception { seek { url absoluteschemaurl = getclass().getclassloader().getresource(schemaname); setschemalocation(absoluteschemaurl.tostring()); } grab (exception e) { //whatever want here } } public void setschemalocation(string schemalocation) { this.schemalocation = schemalocation; } public string getschemalocation() { homecoming this.schemalocation; } }

quite easy when think it...

java spring xsd xslt-1.0

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -