# JAX-WS (SOAP) Server in Spring

In 
Published 2022-12-03

This tutorial shows you how to create a JAX-WS (SOAP) web service server.

SOAP is an XML specification for sending messages over a network. SOAP messages are independent of any operating system and can use a variety of communication protocols including HTTP and SMTP.

JAX-WS is a framework that simplifies using SOAP. It is part of standard Java.

In order to create a SOAP web service in Spring, you have to create a simple Spring application and configure it to use Maven.

Here is the pom.xml file dependencies:

Now we have to create the following classes:

package com.example.config;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter;
 
//JAX-WS Server context configuration class
@Configuration
@ComponentScan("com.example.*")
public class SpringContextConfig {
 
    @Bean
    public SimpleJaxWsServiceExporter jaxWsExporter () {
           
        SimpleJaxWsServiceExporter exporter = new SimpleJaxWsServiceExporter();
         
        exporter.setBaseAddress("http://localhost:8800/services/");
         
        return exporter;
    }
}
package com.example.services;
 
import org.springframework.stereotype.Service;

@Service
public class MyServiceA {
 
    public String addNumbers(int val1, int val2) {
         
        int sum = val1 + val2;
        return "The SUM is "+sum;
    }
}
package com.example.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.example.services.MyServiceA;
 
@WebService
@Component
public class MyServiceA_WS {
 
    @Autowired
    private MyServiceA myServiceA; 
     
    @WebMethod
    public String addNumbers(
            @WebParam(name = "value1") int value1,
            @WebParam(name = "value2") int value2) {
             
        return myServiceA.addNumbers(value1, value2);
    }
}
package com.example.main;
 
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 
import com.example.config.SpringContextConfig;
 
//Main JAX-WS Server
public class Main {
 
    public static void main (String [] args) {
         
          System.out.println("Start ...");
           
          AnnotationConfigApplicationContext context 
            = new AnnotationConfigApplicationContext(SpringContextConfig.class);
             
    }     
}

When I run the application I receive:

As you can see the context is not closed and the application is still running.