Simple Project: Spring Boot + Apache CXF (JAX-WS)

Let’s create a simple hello world with and Spring Boot + Apache CXF (JAX-WS) project. Is not so common to find and example on the web, so I’m going to provide it.

Firstly, we need to declare some dependencies on our pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
<description>Simples Spring Boot + Apache CXF (JAX-WS) project </description>

view raw


hosted with ❤ by GitHub

I’d like to highlight the dependency with artefactid cxf-spring-boot-starter-jaxws, which provides the Apache CXF for Spring Boot. As a pattern in Spring projects, we will create and and set the Endpoint and publish it as we usually do in JAX-WS projects.

import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
public class WebServiceConfig {
private Bus bus;
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, new HelloPortImpl());
return endpoint;

As we can see, we will always do commons configurations of JAX-WS but following the Spring Boot patterns. So, if you’ve worked with Spring Boot and with JAX-WS, it will be simple.



I can imagine that somebody would ask yourself about the org.apache.cxf.Bus. So, I’d like to break the tutorial just to bring a quote of what it is according to the Apache CXF documentation:

The bus, being CXF’s backbone, is a provider of shared resources to the CXF runtime. Examples for such shared resources include WSDL managers and binding factory managers. The bus can easily be extended to include your own custom resources or services, or you can replace default resources like the HTTP destination factory (based on Jetty) with your own (possibly based on another web container such as Apache Tomcat).

This extensibility is made possible by dependency injection; the default bus implementation is based on Spring Framework, which wires the runtime components together for you.

Apache CXF Documentation

from Apache CXF Documentation


No other configuration is necessary to our hello world, so, now we only need to create our class to receive the SOAP request.


import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import java.util.logging.Logger;
@WebService(serviceName = "HelloService", portName = "HelloPort", targetNamespace = ";)
public class HelloPort {
private static final Logger LOG = Logger.getLogger(HelloPort.class.getName());
@WebResult(name = "return", targetNamespace = "")
@RequestWrapper(localName = "sayHello", targetNamespace = ";, className = "")
@WebMethod(action = "urn:SayHello")
@ResponseWrapper(localName = "sayHelloResponse", targetNamespace = ";, className = "")
public java.lang.String sayHello(@WebParam(name = "myname", targetNamespace = "") String myname) {
try {
return "Hello, " + myname + "!";
} catch (java.lang.Exception ex) {
throw new RuntimeException(ex);

view raw

hosted with ❤ by GitHub

I’ve used the same annotation the we use in any JAX-WS project. So, compile and be happy!

Endpoint: http://localhost:<port>/services/Hello?wsdl



We cannot use @Autowired to inject dependencies inside the HelloPort because it’s not managed as bean for Spring. I will post some workarounds to help with it!


Deixe um comentário

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logo do

Você está comentando utilizando sua conta Sair /  Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair /  Alterar )

Conectando a %s