This tutorial shows you how to create a SOAP webservice with JAX-WS RI and Spring Boot. You will write a Java class that adheres to the JAX-WS standard and generate a SOAP endpoint from it (including the wsdl).
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.
Now, onto the Application
class, which 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.
Next comes the Service
class. The service doesn’t do very much besides greeting the client upon being called. 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
- Find out, why you should write your service contract (wsdl) first and not the code
- Learn how to develop a service “contract-first” with JAX-WS RI
- See what other alternatives to RI are available