Spring WS+JAXB

Download projects

Here is sample Spring WS application that shows how to expose your bean method as WS service and handle XML marshaling using JAXB.

There are 4 major parts involved here.

1. Define your XML schemas. Unlike some other WS frameworks Spring WS starts from WSDL’s or XSD’s.

2. web.xml.



Please note, that according to Spring documentation, its better to use “MessageDispatcherServlet” but I found it too limiting. For example I could not use multiple “SoapMessageDispatcher”‘.

3. Boring Spring WebServices beans and JAXB marshaller.




As mentioned above we can define multiple “SoapMessageDispatcher” that use different parsers (some times its cleaner to have multiple JAXB marshallers that are configured with POJOs for each WebService).

4. Your Endpoint. Spring will use your Endpoint PayloadRoot annotation to match WS request to appropriate method.

package com.equilibriums.samplespringws;

import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

public class SampleEndpoint{

@PayloadRoot(localPart = "sampleRequest", namespace = "http://equilibriums.com/sample-spring-ws")
public SampleResponse processSampleRequest(SampleRequest request){
SampleResponse result = new SampleResponse();
result.setResponse( "Request was: " + request.getRequest() );
return result;

And finally you can access WSDL using “http://localhost:8080/sample.wsdl” (assuming its deployed under http://localhost:8080) and call WebService using soapUI standalone application or its Eclipse plugin.

1 comment to Spring WS+JAXB

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>