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

Learn how to create a SOAP webservice with JAX-WS RI and Spring Boot.

Download source code

What to do

Use spring initializr to create a Spring Boot application with Spring Web dependency.

Open your pom.xml and 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.

<!– JAX-WS –>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.3</version>
</dependency>
<!– Spring JAX-WS Integration –>
<dependency>
<groupId>org.jvnet.jax-ws-commons.spring</groupId>
<artifactId>jaxws-spring</artifactId>
<version>1.9</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
</exclusions>
</dependency>
view raw pom.xml hosted with ❤ by GitHub

Configure the Application class, by importing an xml config file (jaxwsconfig.xml) which contains bean wiring for JAX-WS RI and register WSSpringServlet to receive incoming requests.

@SpringBootApplication
@ImportResource(locations = "jaxwsconfig.xml")
public class TutorialJavaJaxwsApplication {
public static void main(String[] args) {
SpringApplication.run(TutorialJavaJaxwsApplication.class, args);
}
@Bean
public ServletRegistrationBean servletRegistrationBean() {
return new ServletRegistrationBean(new WSSpringServlet(), "/hello");
}
}

Create a GreetingService class which greets the client upon being called. You will reference the service by the name later to let it handle the web service requests.

@Component(value = "greetingService")
@WebService
public class GreetingService {
@WebMethod
public String greeting() {
return "Hello World!";
}
}
view raw GreetingService.java hosted with ❤ by GitHub

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

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.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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