Search Tutorials

Spring Boot SOAP Web Service - Hello World Example | JavaInUse

Spring Boot + SOAP Web Service Simple Example

In this post we develop a Spring Boot Application to expose SOAP Webservices.

What is SOAP Webservice? Need for it?

Web Services can be implemented in either of the 2 ways-
  • REST
  • SOAP
A majority of the examples we have done before make use of the REST web services.
SOAP (originally Simple Object Access Protocol) is a protocol specification for exchanging structured information in the implementation of web services in computer networks. SOAP allows processes running on disparate operating systems (such as Windows and Linux) to communicate using Extensible Markup Language (XML).
SOAP can be used in conjunction with WSDL which is standardized what means that people who know the standard (WSDL) can learn from it what operations a web service offers and how data is exchanged.
This knowledge can be used to create tools that generate type safe binder classes/objects out of the WSDL file.
These generated classes (to make RPCs) can be used without needing to manually implementing the requests and encoding/parsing of the data that is exchanged.


This tutorial is explained in the below Youtube Video.

Lets Begin-

Create the maven project as follows-

The classes in package com.javainuse are generated classes from wsdl.
The pom.xml will be as follows-
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


	<description>Demo project for Spring Boot</description>

		<relativePath /> <!-- lookup parent from repository -->






We define a "contract-first" webservice using WSDL. In the contract-first web service, the "contract" i.e a WSDL definition of operations and endpoints and XML schema of the messages is created first, without actually writing any service code.
Next we define the wsdl file that takes a String as an input and returns another string as output.
The WSDL is defined as follows-
<?xml version="1.0" encoding="ISO-8859-1"?>

<wsdl:definitions xmlns:soap=""
	xmlns:tns="" xmlns:xs=""
	xmlns:http="" xmlns:wsdl=""

		<xs:schema targetNamespace="">
			<xs:element name="inputSOATest">
						<xs:element type="xs:string" name="test" />
			<xs:element name="outputSOATest">
						<xs:element type="xs:string" name="result" />

<!--Define input and output parameters -->
	<wsdl:message name="inputSOATest">
		<wsdl:part name="in" element="tns:inputSOATest" />
	<wsdl:message name="outputSOATest">
		<wsdl:part name="out" element="tns:outputSOATest" />

<!--Define port definition -->
	<wsdl:portType name="SOATestEndpoint">
		<wsdl:operation name="SOATest">
			<wsdl:input message="tns:inputSOATest" />
			<wsdl:output message="tns:outputSOATest" />

<!--Bind Soap operation and service -->
	<wsdl:binding name="SOATestBinding" type="tns:SOATestEndpoint">
		<soap:binding transport="" />
		<wsdl:operation name="SOATest">
			<soap:operation soapAction=""
				style="document" />
				<soap:body parts="in" use="literal" />
				<soap:body parts="out" use="literal" />

<!--Define service -->
	<wsdl:service name="SOATestEndpointService">
		<wsdl:port name="SOATestEndpoint" binding="tns:SOATestBinding">
			<soap:address location="http://localhost:8080/javainuse/ws/helloWorldExample" />

Next using the ServletRegistrationBean we register the MessageDispatcherServlet with Spring Boot.
During this registration the servlet mapping URI pattern is set to /javainuse/ws/*. Using this path, the web container will map incoming HTTP requests to the MessageDispatcherServlet. The DefaultWsdl11Definition exposes a standard WSDL 1.1 using the specified Hello World WSDL file. MessageDispatcherServlet also automatically detects any WsdlDefinition defined in its application context. So the path of the url at which WSDL is exposed will be as follows-
package com.javainuse.config;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class WebServiceConfig extends WsConfigurerAdapter {

	public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
		MessageDispatcherServlet servlet = new MessageDispatcherServlet();

		return new ServletRegistrationBean(servlet, "/javainuse/ws/*");

	public Wsdl11Definition defaultWsdl11Definition() {
		SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
		wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/helloworld.wsdl"));

		return wsdl11Definition;
Next we define the endpoint which will process the incoming xml messages.
package com.javainuse.endpoint;


import com.javainuse.InputSOATest;
import com.javainuse.ObjectFactory;
import com.javainuse.OutputSOATest;

public class WebServiceEndpoint {

	private static final String NAMESPACE_URI = "";

	@PayloadRoot(namespace = NAMESPACE_URI, localPart = "inputSOATest")
	public OutputSOATest hello(@RequestPayload InputSOATest request) {

		String outputString = "Hello " + request.getTest() + "!";

		ObjectFactory factory = new ObjectFactory();
		OutputSOATest response = factory.createOutputSOATest();

		return response;
Finally create the class with @SpringBootApplication annotation.
package com.javainuse;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringBootHelloWorldApplication {

	public static void main(String[] args) {, args);
Start the application-

Next go to http://localhost:8080/javainuse/ws/helloworld.wsdl
Finally using the wsdl url create a SOAP UI project.
Download Source Code

Download it -
Spring Boot + SOAP

See Also

Spring Boot Hello World Application- Create simple controller and jsp view using Maven Spring Boot Tutorial-Spring Data JPA Spring Boot + Simple Security Configuration Pagination using Spring Boot Simple Example Spring Boot + ActiveMQ Hello world Example Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot Main Menu Spring Boot Interview Questions