Web service application with JAX-WS and Spring

1. Introduction

It has been a long wait, but I am finally publishing a tutorial on creating the first SOAP based web service application with Spring. JAX-WS (Java API for XML Web Services) is a set of APIs for creating web services in XML format, which we also most commonly call as SOAP based web service, which hope we all are aware of the basic architecture.

2. Implementation

To start with, let’s check out the pom file configuration –



Let’s create the Customer entity for our application.


Let’s now create the service interface and its corresponding service implementation class.



Below is how the applicationContext should look like.


Note that a URL pattern (/customer) is bound to the web service endpoint implementation class (customerEndpoint), as can be seen in the above snippet. Below is how our customerEndpoint bean implementation class looks like.


Note that @WebService annotation tells the server runtime environment to expose all the public methods of that class as web service methods. If we want to prevent any of the methods to be exposed as web service method, we need to annotation the method with @WebMethod(exclude = true), as can be seen in the above snippet. Similarly if we want to name the web service method to something different from the actual method name specified in the class (getCustomerById()), we need to add an operationName attribute to the @WebMethod annotation.

If you face any dependency issues while setting up the project, you can refer this link.

3. Running the application


Once we hit the above URL, we can see the WSDL content displayed, as can be seen in the below snapshot.


We can also test the endpoint with SOAP UI as well. Create the new SOAP project with the same WSDL location as mentioned above.

SOAP JAX WS with Spring Example

4. Download the source code

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.