Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Spring Boot Actuator

When the presence of the Spring Boot Actuator is detected, the application may benefit from metrics support auto-configuration (based on  Micrometer library). The instrumentation layer automatically (or programmatically) tracks the server-side metrics with respect to requests processing, and exposes it along with other metrics. For more details, please check Micrometer Integration documentation.

PropertyDescriptionDefault
cxf.metrics.enabledEnables or disables metrics auto-configurationtrue
cxf.metrics.jaxrs.enabledEnables or disables JAX-RS metrics auto-configurationtrue
cxf.metrics.jaxws.enabledEnables or disables JAX-WS metrics auto-configurationtrue
cxf.metrics.server.autoTimeRequests

Whether requests handled by CXF should be automatically timed.  If the number of time series emitted grows
too large on account of request mapping timings, set it to "false" and use @Timed or @TimeSet on a per
invocation basis as needed.

true
cxf.metrics.server.requestsMetricNameName of the metric for received requests (server-side)cxf.server.requests
cxf.metrics.server.maxUriTags

Maximum number of unique URI tag values allowed. After the max number of tag values is reached,
metrics with additional tag values are denied by filter.

100
cxf.metrics.client.requestsMetricNameName of the metric for sent requests (client-side)cxf.client.requests
cxf.metrics.client.maxUriTags

Maximum number of unique URI tag values allowed. After the max number of tag values is reached,
metrics with additional tag values are denied by filter.

100

Spring Boot CXF JAX-WS Starter

Features

Registers CXFServlet with a  "/services/*" URL pattern for serving CXF JAX-WS endpoints.

...

Code Block
languagexml
titleJAX-WS Starter
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>3.1.7<12</version>
</dependency>

Additional Configuration

Use "cxf.path" property to customize a CXFServlet URL pattern

Use "cxf.servlet.init" map property to customize CXFServlet properties such as "services-list-path" (available by default at  "/services"), etc.

Use "cxf.servlet.loadOnStartup" set loadOnStartup priority of the CXFServlet (by default, -1)

Use "cxf.servlet.enabled" enable/disable CXFServlet regsitration (since 3.3.12/3.4.5)

If needed, one can use Spring ImportResource annotation to import the existing JAX-WS contexts available on the classpath.

API Documentation

JAX-WS endpoints support WSDL.

...

Code Block
languagejava
titleJAX-WS Configuration
package sample.ws;

import javax.xml.ws.Endpoint;
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;
import sample.ws.service.HelloPortImpl;


@Configuration
public class WebServiceConfig {
    @Autowired
    private Bus bus;

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, new HelloPortImpl());
        endpoint.publish("/Hello");
        return endpoint;
    }
}

 


Having a CXF JAX-WS starter alongside this Configuration is sufficient for enabling a CXF JAX-WS endpoint which will respond to SOAP request URI such as

...

Code Block
languagexml
titleJAX-RS Starter
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxrs</artifactId>
    <version>3.1.7<12</version>
</dependency>

Additional Configuration

Use "cxf.path" property to customize a CXFServlet URL pattern.

Use "cxf.servlet.init" map property to customize CXFServlet properties such as "services-list-path" (available by default at  "/services"), etc.

Use "cxf.servlet.loadOnStartup" set loadOnStartup priority of the CXFServlet (by default, -1)

Use "cxf.servlet.enabled" enable/disable CXFServlet regsitration (since 3.3.12/3.4.5)

Use "cxf.jaxrs.server.path" property to customize a JAX-RS server endpoint address (default is "/").

JAX-RS root resources and providers annotated with JAX-RS @Path and @Provider and native CXF Providers annotated with CXF @Provider can be auto-discovered.

Use "cxf.jaxrs.component-scan" property to create a JAX-RS endpoint from the auto-discovered JAX-RS root resources and providers which are marked as Spring Components (annotated with Spring @Component or created and returned from @Bean methods).

Use "cxf.jaxrs.component-scan-packages" property to restrict which of the auto-discovered Spring components are accepted as JAX-RS resource or provider classes. It sets a comma-separated list of the packages that a given bean instance's class must be in. Note, this property, if set, is only effective if a given bean is a singleton. It can be used alongside or as an alternative to the "cxf.jaxrs.component-scan-beans" property. This property is available starting from CXF 3.1.11.

Use "cxf.jaxrs.component-scan-beans" property to restrict which of the auto-discovered Spring components are accepted as JAX-RS resource or provider classes. It sets a comma-separated list of the accepted bean names - the auto-discovered component will only be accepted if its bean name is in this list. It can be used alongside or as an alternative to the "cxf.jaxrs.component-scan-packages" property. This property is available starting from CXF 3.1.11.

Use "cxf.jaxrs.classes-scan" property to create a JAX-RS endpoint from the auto-discovered JAX-RS root resources and provider classes. Such classes do not have to be annotated with Spring @Component. This property needs to be accompanied by a "cxf.jaxrs.classes-scan-packages" property which sets a comma-separated list of the packages to scan.

Note that while "cxf.jaxrs.component-scan" and "cxf.jaxrs.classes-scan" are mutually exclusive, "cxf.jaxrs.component-scan" can be used alongside the "cxf.jaxrs.classes-scan-packages" property to enable the auto-discovery of the JAX-RS resources and providers which may or may not be marked as Spring Components.

If needed, instead of having the resources auto-discovered,  one can use Spring ImportResource annotation to import the existing JAX-RS contexts available on the classpath.

API Documentation

Swagger

See CXF Swagger2Feature documentation on how to enable Swagger2Feature in SpringBoot and how to auto-activate Swagger UI.

...

Code Block
languagejava
titleJAX-RS Configuration
package sample.rs.service;
import java.util.Arrays;

import org.apache.cxf.Bus;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.swagger.Swagger2Feature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import sample.rs.service.hello1.HelloServiceImpl1;
import sample.rs.service.hello2.HelloServiceImpl2;

@SpringBootApplication
public class SampleRestApplication {
    @Autowired
    private Bus bus;

    public static void main(String[] args) {
        SpringApplication.run(SampleRestApplication.class, args);
    }
 
    @Bean
    public Server rsServer() {
        JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
        endpoint.setBus(bus);
        endpoint.setAddress("/");
        // Register 2 JAX-RS root resources supporting "/sayHello/{id}" and "/sayHello2/{id}" relative paths
        endpoint.setServiceBeans(Arrays.<Object>asList(new HelloServiceImpl1(), new HelloServiceImpl2()));
        endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
        return endpoint.create();
    }
}

 


Having a CXF JAX-RS starter alongside this Configuration is sufficient for enabling a CXF JAX-RS endpoint which will respond to HTTP request URI such as

...

Please also see a JAX-RS Spring Boot demo. 


Auto Configuration

Spring Boot Application example shown in the Manual Configuration section can be simplified if the auto-discovery is enabled.

...

Code Block
languagetext
titleApplication Properties
 cxf:
  jaxrs:
    component-scan: true
    classes-scan-packages: org.apache.cxf.jaxrs.swagger

...


the application becomes simply: 


Code Block
languagejava
titleJAX-RS Auto Configuration
package sample.rs.service;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SampleScanRestApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleScanRestApplication.class, args);
    }
}

...


This application will enable a CXF JAX-RS endpoint which will respond to HTTP request URI such as

...

Please also see a JAX-RS Spring Boot Scan demo.