Spring Boot, Apache CXF, Swagger under JAX-RS

3 minute read

This tutorial is about: Making a standard and enterprise JAX-RS Web Service with Spring Boot, Apache CXF, MySQL, and Swagger UI.


Java Developers who know about Spring and REST standards.

Step 1: Add Maven Dependencies to our project

It’s the time to create a Maven Project and put the below dependencies on your POM.xml file.



    <!-- spring dependencies -->

    <!-- Database dependencies -->

    <!-- Apache CXF dependencies -->

    <!-- Jackson dependencies -->

    <!-- Swagger dependencies -->

    <!-- Unit testing dependencies -->

Step 2: Database configurations.

I used H2 to make this application more independent

spring.datasource.username = sa
spring.datasource.password =
spring.datasource.driverClassName = org.h2.Driver

Spring Boot uses Tomcat Pooling by default which is the best Pooling software in Java.

Step 3: Configuration of CXF

class CXFConfig {
  private Bus bus;

  public Server rsServer() {
      final JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
      endpoint.setProvider(new JacksonJsonProvider());
      endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
      return endpoint.create();

  public UserController userController() {
      return new UserController();

The default address of API is /services to change the default CXF API address from /services to /api (or anything that you like) just check my Github profile :)

Step 4: Spring Boot starter method

I prefer to keep Spring Boot starter method out of other configuration classes and put your Beans on other Classes.

public class Starter {

    public static void main(final String[] args) {
        SpringApplication.run(CxfConfig.class, args);

Step 5: Run Spring Boot

It’s time to see what we have done, we can just run a Boot project with mvn spring-boot:run or use any IDE you like. If your Application is running on PORT 8080 just open http://localhost:8080/services/services then you will see your API links then click the only Swagger UI Link.

Final view of running Swagger UI with Spring Boot and Apache CXF

Github repo

Just git clone Spring CXF project and run it on your Machine.