Publishing Static WSDL and related XSD schemas using Spring WS

csviri picture csviri · Mar 2, 2012 · Viewed 13.8k times · Source

I have one module where I have my XSD schemas, where one schema can reference an other using relative path within schema location:

<xs:import namespace="http://my.namespace.org" schemaLocation="../mypackage/my.xsd"/>

Here I'm also using xjc to generate Jaxb beans from these xsd schemas.

Now I have a module where is my web-service is implemetented, using spring-ws (2.0.4). And I want to use static WSDL and publish it with the xsd schemas, where the schema locations will be transformed to URL like 'http://myerver.url.com/my.xsd'.

The question is how to elegantly achieve this?

(Alternatively combine the XSDs into one schema and that to WSDL)

(In theory I could transform these XSD using a script and add them to resources (xsd and wsdl) to a (spring dispatcher) servlet but it doesn't seems to me very comfortable)

Answer

Robin picture Robin · Oct 3, 2012

Spring web service has a way to do it elegantly actually. All you need to do is to define a SimpleXsdSchema bean with the right id (which will be used as the xsd name without .xsd) in the bean definition xml file, something like below

<bean id="my" 
        class="org.springframework.xml.xsd.SimpleXsdSchema">
        <property 
            name="xsd" 
            value="/mypackage/my.xsd">
        </property>
</bean>

More information (including an example) can be found at the following link: Static WSDL with imported XML Schema in Spring Web Service