Spring Web Services – SOAP Services Tutorial

29 Flares Twitter 0 Facebook 0 Google+ 25 LinkedIn 4 Filament.io 29 Flares ×

Spring Web Services (Spring – WS ) is a separate library from Spring community. It is used for consuming and producing SOAP web services. SOAP web services are contract first web services whereby the request and response adheres to a pre-defined contract or schema. SOAP services are typically used by enterprises for integrating with internal / external systems. This tutorial is all about getting to know – Spring Web Services.

1 Technologies used

  1. JDK 1.6 or later
  2. Mavan 3.0 or later
  3. Spring Tool Suite (STS ) or Eclipse Juno or later

2 Objectives

  1. Consume a SOAP Web Service ( Develop a Client)
  2. Generate or Produce SOAP Web Service ( Develop a Web Service)

Note: The examples are developed using the Spring Tool Suite IDE

3 Consuming the Web Service ( Developing a Client)

 3.1 Dependency

Complete list of dependencies – pom.xml

We are using maven-jaxb2-plugin to generate java sources from WSDL.  This example connects to a publicly available stock quote web service and executes the GetQuote webs service method. The WSDL (http://www.webservicex.net/stockquote.asmx?WSDL) is provided as input to maven-jaxb2-plugin. The plugin is also configured to keep the generated source files in com.javahash.stock package.

Run maven generate-sources ( Right Click project – > RunAs -> Maven generate-sources ) . This will generate the stock quote related jaxb java sources ( location: target/generated-sources/xjc).

3.2 StockQuote Client

In this step, we are going to write a client that invokes the GetQuote Service using the generated jaxb classes.


 3.3 Configuring the client as Spring Bean

Next step is to configure StockQuoteCllient.java as a Spring bean. We are using the JavaConfig feature of spring instead of the traditional xml configuration files.


We have configured the StockQuoteClient as a Spring bean and provided it with its dependent objects ( marshaller and un-marshaller instance to use). When spring container loads up, StockQuoteClient will be registered as Spring bean.

 3.3 Invoking the Service

This is final step – invoking the service using the StockQuoteClient bean from a main method.

App,java – Main program

Note: Make sure that you run maven install or maven package before running the application.

Future Work

Produce or Expose a SOAP WebS ervice – TODO

  • Thiago Cristian Pedroso

    Good Tutorial, do you will make a new tutorial about Generate or Produce SOAP Web Service ( Develop a Web Service)?