Simple web service example using JAX-WS Spring and Maven


Recently I had to port an existing web service (that is running on Glassfish) to tomcat while using Spring and Maven.
The resources I found online here, here and here are very helpful. But I had few hiccups in running the sample application I downloaded from the links. Hence this version with all workarounds and fixes, which I can refer back in the future if needed.
The best approach to understand this tutorial is, to download the application source first (available under Download section), build it, run the application and then go through the tutorial.


Jdk 1.6 (or) Higher & Maven (2.2.x). Thats all? yes thats all you need to have in your computer. Let us just configure all application dependencies in Maven configuration file (pom.xml) and let the Maven take care of pulling them from internet central repository when we compile the application.

Technology Used

Maven – Build tool, Spring – for dependency injection & bean configuration, Jax-Ws Commons Spring extension, Jetty – Embedded server

Building the application in just 7 steps
Step 1: Creating the project structure using Maven

Run below maven command to create a typical java web application project structure.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.bdot -DartifactId=jaxws-spring-server -DinteractiveMode=false

Once project structure is created, create IDE specific project files using below command.

mvn idea:idea --> for Intellij Idea users 
mvn eclipse:eclipse --> for eclipse users 
Step 2: Creating a simple web service
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@SOAPBinding(style = SOAPBinding.Style.RPC, use = SOAPBinding.Use.LITERAL)
public class UserOperationService {
    private static final String HELLO = "Hello";

    @WebMethod(operationName = "sayHello")
    public String sayHelloToTheUser(@WebParam(name = "name") String userName) {
        return HELLO + " " + userName;
Step 3: Add Spring support to the application

Add spring dependencies to pom.xml.

Note:- ${spring.version} is added as a property in pom.xml, Take a look at the pom.xml in the downloaded application




And spring listener to the web.xml

        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "" >

    <display-name>Jax-WS Spring Server Web Application</display-name>


Step 4: Wire up the web service using spring

Before we configure our web service in spring applicationcontext.xml, we need various JAX-WS commons dependencies. So lets update our pom.xml as shown below. Note:- As we already added Spring dependencies already to the pom.xml, Let us exclude them from jax-ws commons.


applicationContext.xml configuration. This instructs Spring to deligate the any web service call with mapping “webservice/user-service” to UserOperationService.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""

    <!-- Tell spring that we may be using Annotations also -->

    <wss:binding url="/webservice/user-service">
            <ws:service bean="#userOperationService">

    <bean id="userOperationService" class=""/>
Step 5: Setting up a servlet mapping for our web services

Cool, we have created our web service and configured spring. But How to divert the incoming URL requests to Spring? Adding below shown servlet mapping in the web.xml does the magic!

Step 6: Solving Linkage error

Many of the dependencies we added implicitly download the javax.activation java library. But javax.activation is available in Java 1.6 by default, which causes the linkage errors by class loader. So, we may have to exclude javax.activation from all our dependencies. Please take a look at the pom.xml in the downloaded application.

Step 7: Building and verifying

Aah finally, Building the application is very easy. Just extract the application downloaded and go to the application folder (where you can see pom.xml) from command prompt, and run below maven command. First run may take a while as maven tries to download all dependencies from central repository.

mvn clean install

“Build is successful”. Now let us run the application with the following command

mvn jetty:run

Hurray. Lets see the application we built, Go to your favourite browser and access the WSDL generated @


You can use either SOAP UI or any other simple client application to consume the web service.


Source, pick it up from Bitbucket here
or to download click here


Maven Installation / Environment Setup
Below are the links that helped me understanding how to develop this application.
JAX-WS Commons
j2eeroad blog


  • Sergei


  • Moti

    It’s very helful :roll: