Consuming SOAP Service With Apache CXF and Spring

SOAP web services are not popular anymore but if you are working with old applications, you probably still have to deal with SOAP web services. I am going to give you an example of how to consume a SOAP service with CXF, how to make a configuration for it, and how to log requests and responses to it.

A Simple Web Service

Before I can consume a web service, I need a simple web service to work with. For the project, I am going to use Spring Boot version 2.5.0 and Java 11. You can use another version if you like; it does not matter as long as the versions are not too old. You can easily create a Spring Boot project with a Spring Initializer. If you use maven, pom.xml should be like this. If you use Java 8, you do not need to have a "JAXB Runtime" dependency.

SOAP Web Services With Apache CXF and Spring Boot

This post is based on one I wrote a few years ago about building contract first web services with Apache CXF and Spring. The previous post didn't use Spring Boot and most of the Spring and CXF configuration was via XML. This post moves things forward a bit by using the latest version of CXF and Spring Boot.

Sample App

We're going to build a simple Spring Boot app that exposes SOAP web service using Apache CXF. The service will have a single operation that takes an account number and returns bank account details. If you're impatient and want to jump ahead you can grab the full source code from GitHub.