Contract-first webservice with Spring Boot and JAX-WS RI

This tutorial shows you how to create a contract-first SOAP web service with JAX-WS RI and Spring Boot. You will define the service contract first and then implement it.

Get the sources for this tutorial

What to do

At first, set up your pom.xml file. Besides stuff for Spring Boot, you’ll include jaxws-rt (the runtime) and jaxws-spring (a helper library for integrating jaxws-rt with Spring). Exclude the Spring dependencies from jaxws-spring to avoid conflicts. You will also need the jaxws-maven-plugin to help you generate the service classes.

Next, you want to create the service contract by defining the Web Service (WSDL) and Type Definitions (XSD). If you don’t know how to read WSDL documents, here is an excellent introduction.

Run mvn clean compile to generate the Service API. You should see in the target/generated-sources/wsimport folder the service interface and type classes.

The Application class is the main entry to your application. As you’ll see, you will import an xml config file (jaxwsconfig.xml) which contains bean wiring for JAX-WS RI. Also, you need to register WSSpringServlet to receive incoming requests.

The GreetingServiceImpl class implements the web service. It references the service endpoint interface which tells the JAX-WS runtime to use it as an explicit interface (read more about SEIs here). Through the @Component annotation you can make sure it gets picked up, added to the Spring context and will be given a name. You will reference the service by the name later to let it handle the web service requests.

Lastly, you have to add an xml file for wiring the service on the endpoint:

Build and run it

Build it: mvn clean package
Run it: java -jar helloJaxws-0.0.1-SNAPSHOT.jar

Now open http:/localhost:8080/hello?wsdl to see the generated wsdl file. Your webservice has been deployed, and you could now create a client for it.

What to do next?

Here are some hints what topics you could explore next.

  • Test your webservice with SoapUI
  • See what other alternatives to RI are available

4 thoughts on “Contract-first webservice with Spring Boot and JAX-WS RI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s