Search code examples
web-servicesspring-mvcjax-ws

Spring 3 MVC + Web Services (JAX-WS)


We have a Spring 3 MVC webapplication, and we are trying to expand it with Web Services.

I have now tried with JAX-WS Web-services, annotating WebService and WebMethod on the appropriate places. I do have a dispatcher mapped in my web.xml. This is the standard spring DispatcherServlet. And its config: dispatcher-servlet.xml is working perfectly fine for the MVC stuff.

The problem comes when I try to expose the WebServices. I do this by adding the following bean to the dispatcher-servlet.xml:

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
    <property name="baseAddress" value="http://localhost:8080/service/" />
</bean>

If this bean is added. Then the WebServices works perfectly, but all the MVC stuff stops working.

So my second try was to create 2 dispatchers. One named mvc-dispatcher and one webservice-dispatcher. Each of them mapped to respectivly /mvc and /ws. And then put only the SimpleJaxWsServiceExporter in the webservice-config and only the standard MVC stuff in the other one. But still the same problems. I can only get the MVC to work if I disable/comment-out the web-service dispatcher.

I cant belive this is supposed to be so complicated... What am I not getting?

Any help would be greatly appriciated. I cant find any decent tutorials doing JAX-WS and spring 3 MVC...

Thanks in advance!


Solution

  • I'm assuming by dispatcher you mean a spring dispatcher, I'd recommend against that. Just have the JAX-WS be a different servlet on it's own, i.e.

    https://cxf.apache.org/docs/a-simple-jax-ws-service.html

    Then if you need to allow Spring beans to be injected extend SpringBeanAutowiringSupport as in this example.

    How to make an @WebService spring aware

    Hope this helps!