blob: 96ae6988f56cc15fd65396dc92245d66931b29cd [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<link type="text/css" rel="stylesheet" href="/resources/site.css">
<script src='/resources/space.js'></script>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="keywords" content="business integration, EAI, SOA, Service Oriented Architecture, web services, SOAP, JBI, JMS, WSDL, XML, EDI, Electronic Data Interchange, standards support, integration standards, application integration, middleware, software, solutions, services, CXF, open source">
<meta name="description" content="Apache CXF, Services Framework - SpringBoot">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shCoreCXF.css">
<link type="text/css" rel="stylesheet" href="/resources/highlighter/styles/shThemeCXF.css">
<script src='/resources/highlighter/scripts/shCore.js'></script>
<script src='/resources/highlighter/scripts/shBrushXml.js'></script>
<script src='/resources/highlighter/scripts/shBrushJava.js'></script>
<script src='/resources/highlighter/scripts/shBrushPlain.js'></script>
<script>
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
</script>
<title>
Apache CXF -- SpringBoot
</title>
</head>
<body onload="init()">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td id="cell-0-0" colspan="2">&nbsp;</td>
<td id="cell-0-1">&nbsp;</td>
<td id="cell-0-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-1-0">&nbsp;</td>
<td id="cell-1-1">&nbsp;</td>
<td id="cell-1-2">
<!-- Banner -->
<div class="banner" id="banner"><div><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="left" colspan="1" nowrap>
<a shape="rect" href="http://cxf.apache.org/" title="Apache CXF"><span style="font-weight: bold; font-size: 170%; color: white">Apache CXF</span></a>
</td><td align="right" colspan="1" nowrap>
<a shape="rect" href="http://www.apache.org/" title="The Apache Sofware Foundation"><img border="0" alt="ASF Logo" src="http://cxf.apache.org/images/asf-logo.png"></a>
</td></tr></table></div></div>
<!-- Banner -->
<div id="top-menu">
<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr>
<td>
<div align="left">
<!-- Breadcrumbs -->
<a href="index.html">Index</a>&nbsp;&gt;&nbsp;<a href="deployment.html">Deployment</a>&nbsp;&gt;&nbsp;<a href="application-server-specific-configuration-guide.html">Application Server Specific Configuration Guide</a>&nbsp;&gt;&nbsp;<a href="springboot.html">SpringBoot</a>
<!-- Breadcrumbs -->
</div>
</td>
<td>
<div align="right">
<!-- Quicklinks -->
<div id="quicklinks"><p><a shape="rect" href="http://cxf.apache.org/download.html">Download</a> | <a shape="rect" href="http://cxf.apache.org/docs/index.html">Documentation</a></p></div>
<!-- Quicklinks -->
</div>
</td>
</tr>
</table>
</div>
</td>
<td id="cell-1-3">&nbsp;</td>
<td id="cell-1-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-2-0" colspan="2">&nbsp;</td>
<td id="cell-2-1">
<table>
<tr valign="top">
<td height="100%">
<div id="wrapper-menu-page-right">
<div id="wrapper-menu-page-top">
<div id="wrapper-menu-page-bottom">
<div id="menu-page">
<!-- NavigationBar -->
<div id="navigation"><ul class="alternate"><li><a shape="rect" href="overview.html">Overview</a></li><li><a shape="rect" href="how-tos.html">How-Tos</a></li><li><a shape="rect" href="frontends.html">Frontends</a></li><li><a shape="rect" href="databindings.html">DataBindings</a></li><li><a shape="rect" href="transports.html">Transports</a></li><li><a shape="rect" href="configuration.html">Configuration</a></li><li><a shape="rect" href="debugging-and-logging.html">Debugging and Logging</a></li><li><a shape="rect" href="tools.html">Tools</a></li><li><a shape="rect" href="restful-services.html">RESTful Services</a></li><li><a shape="rect" href="wsdl-bindings.html">WSDL Bindings</a></li><li><a shape="rect" href="service-routing.html">Service Routing</a></li><li><a shape="rect" href="dynamic-languages.html">Dynamic Languages</a></li><li><a shape="rect" href="ws-support.html">WS-* Support</a></li><li><a shape="rect" href="advanced-integration.html">Advanced Integration</a></li><li><a shape="rect" href="deployment.html">Deployment</a></li><li><a shape="rect" href="schemas-and-namespaces.html">Use of Schemas and Namespaces</a></li></ul><hr><ul class="alternate"><li><p>Search</p></li></ul><form enctype="application/x-www-form-urlencoded" method="get" id="cse-search-box" action="http://www.google.com/cse">
<div>
<input type="hidden" name="cx" value="002890367768291051730:o99qiwa09y4">
<input type="hidden" name="ie" value="UTF-8">
<input type="text" name="q" size="21">
<input type="submit" name="sa" value="Search">
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script><hr><ul class="alternate"><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest/">API 3.2.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/javadoc/latest-3.1.x/">API 3.1.x (Javadoc)</a></li><li><a shape="rect" href="http://cxf.apache.org/">CXF Website</a></li></ul><p>&#160;</p><p><a shape="rect" class="external-link" href="http://www.apache.org/events/current-event.html"><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image confluence-external-resource" src="http://www.apache.org/events/current-event-125x125.png" data-image-src="http://www.apache.org/events/current-event-125x125.png"></span></a></p></div>
<!-- NavigationBar -->
</div>
</div>
</div>
</div>
</td>
<td height="100%">
<!-- Content -->
<div class="wiki-content">
<div id="ConfluenceContent"><p><style type="text/css">/*<![CDATA[*/
div.rbtoc1636141701508 {padding: 0px;}
div.rbtoc1636141701508 ul {list-style: disc;margin-left: 0px;}
div.rbtoc1636141701508 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style></p><div class="toc-macro rbtoc1636141701508">
<ul class="toc-indentation"><li><a shape="rect" href="#SpringBoot-SpringBootActuator">Spring Boot Actuator</a></li><li><a shape="rect" href="#SpringBoot-SpringBootCXFJAX-WSStarter">Spring Boot CXF JAX-WS Starter</a>
<ul class="toc-indentation"><li><a shape="rect" href="#SpringBoot-Features">Features</a></li><li><a shape="rect" href="#SpringBoot-Setup">Setup</a></li><li><a shape="rect" href="#SpringBoot-AdditionalConfiguration">Additional Configuration</a></li><li><a shape="rect" href="#SpringBoot-APIDocumentation">API Documentation</a></li><li><a shape="rect" href="#SpringBoot-ServiceRegistryPublication">Service Registry Publication</a></li><li><a shape="rect" href="#SpringBoot-Examples">Examples</a></li></ul>
</li><li><a shape="rect" href="#SpringBoot-SpringBootCXFJAX-RSStarter">Spring Boot CXF&#160;JAX-RS Starter</a>
<ul class="toc-indentation"><li><a shape="rect" href="#SpringBoot-Features.1">Features</a></li><li><a shape="rect" href="#SpringBoot-Setup.1">Setup</a></li><li><a shape="rect" href="#SpringBoot-AdditionalConfiguration.1">Additional Configuration</a></li><li><a shape="rect" href="#SpringBoot-APIDocumentation.1">API Documentation</a>
<ul class="toc-indentation"><li><a shape="rect" href="#SpringBoot-Swagger">Swagger</a></li><li><a shape="rect" href="#SpringBoot-WADL">WADL</a></li></ul>
</li><li><a shape="rect" href="#SpringBoot-ServiceRegistryPublication.1">Service Registry Publication</a></li><li><a shape="rect" href="#SpringBoot-Examples.1">Examples</a>
<ul class="toc-indentation"><li><a shape="rect" href="#SpringBoot-ManualConfiguration">Manual Configuration</a></li><li><a shape="rect" href="#SpringBoot-AutoConfiguration">Auto Configuration</a></li></ul>
</li></ul>
</li></ul>
</div><h1 id="SpringBoot-SpringBootActuator">Spring Boot Actuator</h1><p>When the presence of the <a shape="rect" class="external-link" href="https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html" rel="nofollow">Spring Boot Actuator</a> is detected, the application may benefit from metrics support auto-configuration (based on&#160; <a shape="rect" class="external-link" rel="nofollow" href="https://micrometer.io/">Micrometer</a> 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 <a shape="rect" href="micrometer.html">Micrometer Integration</a> documentation.</p><div class="table-wrap"><table class="wrapped confluenceTable"><colgroup span="1"><col span="1"><col span="1"><col span="1"></colgroup><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh">Property</th><th colspan="1" rowspan="1" class="confluenceTh">Description</th><th colspan="1" rowspan="1" class="confluenceTh">Default</th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.enabled</strong></td><td colspan="1" rowspan="1" class="confluenceTd">Enables or disables metrics auto-configuration</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>true</strong></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.jaxrs.enabled</strong></td><td colspan="1" rowspan="1" class="confluenceTd">Enables or disables JAX-RS metrics auto-configuration</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>true</strong></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.jaxws.enabled</strong></td><td colspan="1" rowspan="1" class="confluenceTd">Enables or disables JAX-WS metrics auto-configuration</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>true</strong></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.server.autoTimeRequests</strong></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Whether requests handled by CXF should be automatically timed.&#160; If the number of time series emitted grows <br clear="none">too large on account of request mapping timings, set it to "false" and use <a shape="rect" class="external-link" href="https://github.com/micrometer-metrics/micrometer/blob/master/micrometer-core/src/main/java/io/micrometer/core/annotation/Timed.java" rel="nofollow">@Timed</a> or&#160;<a shape="rect" class="external-link" href="https://github.com/micrometer-metrics/micrometer/blob/master/micrometer-core/src/main/java/io/micrometer/core/annotation/TimedSet.java" rel="nofollow">@TimeSet</a> on a per <br clear="none">invocation basis as needed.</p></td><td colspan="1" rowspan="1" class="confluenceTd"><strong>true</strong></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.server.requestsMetricName</strong></td><td colspan="1" rowspan="1" class="confluenceTd">Name of the metric for received requests (server-side)</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.server.requests</strong></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.server.maxUriTags</strong></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Maximum number of unique URI tag values allowed. After the max number of tag values is reached, <br clear="none">metrics with additional tag values are denied by filter.</p></td><td colspan="1" rowspan="1" class="confluenceTd">100</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.client.requestsMetricName</strong></td><td colspan="1" rowspan="1" class="confluenceTd">Name of the metric for sent requests (client-side)</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.client.requests</strong></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><strong>cxf.metrics.client.maxUriTags</strong></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Maximum number of unique URI tag values allowed. After the max number of tag values is reached, <br clear="none">metrics with additional tag values are denied by filter.</p></td><td colspan="1" rowspan="1" class="confluenceTd">100</td></tr></tbody></table></div><h1 id="SpringBoot-SpringBootCXFJAX-WSStarter">Spring Boot CXF JAX-WS Starter</h1><h2 id="SpringBoot-Features">Features</h2><p>Registers CXFServlet with a &#160;"/services/*" URL pattern for serving CXF JAX-WS endpoints.</p><h2 id="SpringBoot-Setup">Setup</h2><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>JAX-WS Starter</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&lt;dependency&gt;
&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
&lt;artifactId&gt;cxf-spring-boot-starter-jaxws&lt;/artifactId&gt;
&lt;version&gt;3.1.12&lt;/version&gt;
&lt;/dependency&gt;</pre>
</div></div><h2 id="SpringBoot-AdditionalConfiguration">Additional Configuration</h2><p>Use "<strong>cxf.path</strong>" property to customize a CXFServlet URL pattern</p><p>Use "<strong>cxf.servlet.init</strong>" map property to customize CXFServlet properties such as "services-list-path" (available by default at&#160; "/services"), etc.</p><p>Use "<strong>cxf.servlet.loadOnStartup</strong>" set loadOnStartup priority of the&#160;CXFServlet (by default, -1)</p><p>Use "<strong>cxf.servlet.enabled</strong>" enable/disable CXFServlet regsitration (since <span class="value editable-field inactive" title="Click to edit"><span class="shorten"><strong> 3.3.12</strong>/<strong>3.4.5</strong><a shape="rect" class="external-link" title="3.5.0 " href="https://issues.apache.org/jira/issues/?jql=project+%3D+CXF+AND+fixVersion+%3D+3.5.0">)</a> </span></span></p><p>If needed, one can use Spring ImportResource annotation to import the existing JAX-WS contexts available on the classpath.</p><h2 id="SpringBoot-APIDocumentation">API Documentation</h2><p>JAX-WS endpoints support WSDL.</p><h2 id="SpringBoot-ServiceRegistryPublication">Service Registry Publication</h2><p>Publication of JAX-WS endpoints into well-known service registries such as Netflix Eureka Registry can be achieved similarly to the way JAX-RS endpoints are registered and is shown in a <a shape="rect" class="external-link" href="https://github.com/apache/cxf/tree/master/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application" rel="nofollow">JAX-RS Spring Boot Scan</a> demo.</p><h2 id="SpringBoot-Examples">Examples</h2><p>Consider the following Configuration instance:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>JAX-WS Configuration</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">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;
}
}</pre>
</div></div><p><br clear="none"></p><p>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</p><p>"http://localhost:8080/services/Hello".</p><p>Please also see a <a shape="rect" class="external-link" href="https://github.com/apache/cxf/tree/master/distribution/src/main/release/samples/jaxws_spring_boot" rel="nofollow">JAX-WS Spring Boot</a> demo.</p><h1 id="SpringBoot-SpringBootCXFJAX-RSStarter">Spring Boot CXF&#160;JAX-RS Starter</h1><h2 id="SpringBoot-Features.1">Features</h2><p>Registers CXF Servlet with a &#160;"/services/*" URL pattern for serving CXF JAX-RS endpoints.</p><p>Optionally auto-discovers JAX-RS root resources and providers and creates a JAX-RS endpoint.</p><p>Note the use of CXF JAX-RS Clients in SpringBoot Application is covered in <a shape="rect" href="jaxrsclientspringboot.html">this section</a>.</p><h2 id="SpringBoot-Setup.1">Setup</h2><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>JAX-RS Starter</b></div><div class="codeContent panelContent pdl">
<pre class="brush: xml; gutter: false; theme: Default">&lt;dependency&gt;
&lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
&lt;artifactId&gt;cxf-spring-boot-starter-jaxrs&lt;/artifactId&gt;
&lt;version&gt;3.1.12&lt;/version&gt;
&lt;/dependency&gt;</pre>
</div></div><h2 id="SpringBoot-AdditionalConfiguration.1">Additional Configuration</h2><p>Use "<strong>cxf.path</strong>" property to customize a CXFServlet URL pattern.</p><p>Use "<strong>cxf.servlet.init</strong>" map property to customize CXFServlet properties such as "services-list-path" (available by default at&#160; "/services"), etc.</p><p>Use "<strong>cxf.servlet.loadOnStartup</strong>" set loadOnStartup priority of the&#160;CXFServlet (by default, -1)</p><p>Use "<strong>cxf.servlet.enabled</strong>" enable/disable CXFServlet regsitration (since <span class="value editable-field inactive" title="Click to edit"><span class="shorten"><strong> 3.3.12</strong>/<strong>3.4.5</strong><a shape="rect" class="external-link" title="3.5.0 " href="https://issues.apache.org/jira/issues/?jql=project+%3D+CXF+AND+fixVersion+%3D+3.5.0">)</a> </span></span></p><p>Use "<strong>cxf.jaxrs.server.path</strong>" property to customize a JAX-RS server endpoint address (default is "/").</p><p>JAX-RS root resources and providers annotated with JAX-RS @Path and @Provider and native CXF Providers annotated with CXF <a shape="rect" class="external-link" href="https://github.com/apache/cxf/blob/cxf-3.1.6/core/src/main/java/org/apache/cxf/annotations/Provider.java" rel="nofollow">@Provider</a> can be auto-discovered.</p><p>Use "<strong>cxf.jaxrs.component-scan</strong>" property to create a JAX-RS endpoint from the auto-discovered&#160;JAX-RS root resources and providers which are marked as Spring Components (annotated with Spring @Component or created and returned from @Bean methods).</p><p>Use "<strong>cxf.jaxrs.component-scan</strong>-<strong>packages</strong>" 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 "<strong>cxf.jaxrs.component-scan</strong>-<strong>beans</strong>" property. This property is available starting from CXF 3.1.11.</p><p>Use "<strong>cxf.jaxrs.component-scan</strong>-<strong>beans</strong>" 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 "<strong>cxf.jaxrs.component-scan</strong>-<strong>packages</strong>" property. This property is available starting from CXF 3.1.11.</p><p>Use "<strong>cxf.jaxrs.classes-scan</strong>" property to create a JAX-RS endpoint from the auto-discovered&#160;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 "<strong>cxf.jaxrs.classes-scan-packages</strong>" property which sets a comma-separated list of the packages to scan.</p><p>Note that while "<strong>cxf.jaxrs.component-scan</strong>" and "<strong>cxf.jaxrs.classes-scan</strong>" are mutually exclusive, "<strong>cxf.jaxrs.component-scan</strong>" can be used alongside the "<strong>cxf.jaxrs.classes-scan-packages</strong>" property to enable the auto-discovery of the JAX-RS resources and providers which may or may not be marked as Spring Components.</p><p>If needed, instead of having the resources auto-discovered,&#160; one can use Spring ImportResource annotation to import the existing JAX-RS contexts available on the classpath.</p><h2 id="SpringBoot-APIDocumentation.1">API Documentation</h2><h3 id="SpringBoot-Swagger">Swagger</h3><p>See CXF <a shape="rect" href="swagger2feature.html#SwaggerFeature/Swagger2Feature-EnablinginSpringBoot" rel="nofollow">Swagger2Feature documentation</a> on how to enable Swagger2Feature in SpringBoot and how to auto-activate Swagger UI.</p><h3 id="SpringBoot-WADL">WADL</h3><p>CXF automatically loads a WADL provider if a <strong>cxf-rt-rs-service-description</strong> module is available on the runtime classpath.</p><h2 id="SpringBoot-ServiceRegistryPublication.1">Service Registry Publication</h2><p>Publication of JAX-RS endpoints into well-known service registries such as Netflix Eureka Registry is shown in a <a shape="rect" class="external-link" href="https://github.com/apache/cxf/tree/master/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application" rel="nofollow">JAX-RS Spring Boot Scan</a> demo.</p><h2 id="SpringBoot-Examples.1">Examples</h2><h3 id="SpringBoot-ManualConfiguration">Manual Configuration</h3><p>Consider the following Configuration instance:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>JAX-RS Configuration</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">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.&lt;Object&gt;asList(new HelloServiceImpl1(), new HelloServiceImpl2()));
endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
return endpoint.create();
}
}</pre>
</div></div><p><br clear="none"></p><p>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</p><p>"<a shape="rect" class="external-link" href="http://localhost:8080/services/Hello" rel="nofollow">http://localhost:8080/services/sayHello/ApacheCxfUser</a>". The above code also makes Swagger docs available at&#160;"<a shape="rect" class="external-link" href="http://localhost:8080/services/Hello" rel="nofollow">http://localhost:8080/services/swagger.json</a>".</p><p>Please also see a <a shape="rect" class="external-link" href="https://github.com/apache/cxf/tree/master/distribution/src/main/release/samples/jax_rs/spring_boot" rel="nofollow">JAX-RS Spring Boot</a> demo.</p><p><br clear="none"></p><h3 id="SpringBoot-AutoConfiguration">Auto Configuration</h3><p>Spring Boot Application example shown in the Manual Configuration section can be simplified if the auto-discovery is enabled.</p><p>For example, given the following application.yml properties:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Application Properties</b></div><div class="codeContent panelContent pdl">
<pre class="brush: text; gutter: false; theme: Default">&#160;cxf:
jaxrs:
component-scan: true
classes-scan-packages: org.apache.cxf.jaxrs.swagger</pre>
</div></div><p><br clear="none"></p><p>the application becomes simply:</p><p><br clear="none"></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>JAX-RS Auto Configuration</b></div><div class="codeContent panelContent pdl">
<pre class="brush: java; gutter: false; theme: Default">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);
}
}</pre>
</div></div><p><br clear="none"></p><p>This application will enable a CXF JAX-RS endpoint which will respond to HTTP request URI such as</p><p>"<a shape="rect" class="external-link" href="http://localhost:8080/services/Hello" rel="nofollow">http://localhost:8080/services/sayHello/ApacheCxfUser</a>". The above code also makes Swagger docs available at&#160;"<a shape="rect" class="external-link" href="http://localhost:8080/services/Hello" rel="nofollow">http://localhost:8080/services/swagger.json</a>".</p><p>Please also see a <a shape="rect" class="external-link" href="https://github.com/apache/cxf/tree/master/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application" rel="nofollow">JAX-RS Spring Boot Scan</a> demo.</p><p><br clear="none"></p></div>
</div>
<!-- Content -->
</td>
</tr>
</table>
</td>
<td id="cell-2-2" colspan="2">&nbsp;</td>
</tr>
<tr>
<td id="cell-3-0">&nbsp;</td>
<td id="cell-3-1">&nbsp;</td>
<td id="cell-3-2">
<div id="footer">
<!-- Footer -->
<div id="site-footer">
<a href="http://cxf.apache.org/privacy-policy.html">Privacy Policy</a> -
(<a href="https://cwiki.apache.org/confluence/pages/editpage.action?pageId=64553842">edit page</a>)
(<a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=64553842&amp;showComments=true&amp;showCommentArea=true#addcomment">add comment</a>)<br>
Apache CXF, CXF, Apache, the Apache feather logo are trademarks of The Apache Software Foundation.<br>
All other marks mentioned may be trademarks or registered trademarks of their respective owners.
</div>
<!-- Footer -->
</div>
</td>
<td id="cell-3-3">&nbsp;</td>
<td id="cell-3-4">&nbsp;</td>
</tr>
<tr>
<td id="cell-4-0" colspan="2">&nbsp;</td>
<td id="cell-4-1">&nbsp;</td>
<td id="cell-4-2" colspan="2">&nbsp;</td>
</tr>
</table>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-4458903-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>