Jun 29 2008

Contract First Web Services with Spring 2 and JAX-WS

Published by at 10:15 PM under Java,NetBeans,Spring,web services

This short blog entry will show you how easily you can integrate JAX-WS into a Spring 2 Project. The example sourcecode is depending on my previous blog How to modify JAX-WS SOAP-Messages and i am using NetBeans 6.1.


Download the JAX-WS commons and XBean.

Transform the SOAP Web Services Project into a Spring Project

First open the Non-Spring-Project “How to modify JAX-WS SOAP-Messages“, switch to the project-properties and add the XBean, JAX-WS commons and Spring Framework 2.5 JAR-files.

add jar files to netbeans project

You can see in this picture which JAR-files have to be included in the project:

jar files in the netbeans project

Now you have to create the Spring Configuration file. Create the new XML-file: /WEB-INF/applicationContext.xml. If you are using NetBeans 6.1, navigate to File->New File->Spring Framework->Spring XML Configuration File.

create a new spring configuration file in netbeans 6.1

Replace the content with this:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd">
    <ws:service id="SOAPservice" impl="eu.jdevelop.soapwebservices.service.ServiceImpl">
            <ref bean="myHandler" />

    <wss:bindings id="jax-ws.http">
            <wss:binding url="/soapwebservices" service="#SOAPservice"/>

    <bean id="myHandler" class="eu.jdevelop.soapwebservices.handler.ServerSOAPHandler" />


Modify the web.xml to load the Spring Configuration file.


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

Open the file “ServiceImpl.java” and remove this line:

@HandlerChain(name = "ServerSOAPHandler", file = "serversoaphandler.xml")

You don’t need this annotation anymore, Spring is injecting the “ServerSOAPHandler.java” into the ServiceImpl.java.

the modified ServiceImpl.java

This application is now Spring-enabled. Enjoy the benefits of JAX-WS with Spring 2.

Technorati Tags: , , , , , ,

4 responses so far

4 Responses to “Contract First Web Services with Spring 2 and JAX-WS”

  1. [...] can read the rest of this blog post by going to the original source, here [...]

  2. George sagt:

    Hi dude.
    Nice post. But do you have any idea on how to integrate the JAX-WS REST web services with spring.

    Thanks in advance

  3. Andrew sagt:

    Hello Siegfried,

    Thanks for the example that I found somewhat better than the one supplied at https://jax-ws-commons.dev.java.net/spring.

    Just one remark when using the code: specifying the wsdlLocation attribute in the @WebService annotation of ServiceImpl.java causes an RTE:

    SEVERE: Exception occured in J2EEC Phasejava.lang.RuntimeException: wsdl file WEB-INF/wsdl/ServiceImpl/webservices.wsdl does not exist for web service SOAPService
    com.sun.enterprise.deployment.backend.IASDeploymentException: Error loading deployment descriptors for module [spring-jaxws] — wsdl file WEB-INF/wsdl/ServiceImpl/webservices.wsdl does not exist for web service SOAPService

    It should be removed. Any idea why this occurs ?


  4. Shameer sagt:

    Sharing a similar post with title, Building a web service with Spring-WS at http://justcompiled.blogspot.com/2010/09/building-web-service-with-spring-ws.html