此内容没有您所选择的语言版本。

53.2. JBoss Fuse CXF Implementations


Overview

This section describes how to use the SwaggerFeature in JBoss Fuse CXF implementations, in which REST services are defined inside JAR files and deployed to a JBoss Fuse container or a fabric8 container.
Your JBoss 6.2.1 installation contains a Quickstart (installDir/quickstarts/cxf/rest/) that demonstrates how to create a RESTful (JAX-RS) web service using CXF and how to enable Swagger and annotate the JAX-RS endpoints.

Enabling Swagger

Enabling Swagger involves:
  • Modifying the XML file that defines the CXF service by adding the CXF class (io.fabric8.cxf.endpoint.SwaggerFeature) to the <jaxrs:server> definition.
    For example:
    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxrs="http://cxf.apache.org/blueprint/jaxrs"
    xmlns:cxf="http://cxf.apache.org/blueprint/core"
    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 
    http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
    http://cxf.apache.org/blueprint/jaxrs http://cxf.apache.org/schemas/blueprint/jaxrs.xsd
    http://cxf.apache.org/blueprint/core http://cxf.apache.org/schemas/blueprint/core.xsd">
                          
       <!-- The <jaxrs:server/> element sets up our JAX-RS services. It defines: 
          - the server's address, '/crm', relative to the default CXF servlet URI with the 
            default settings  the server will be running on 'http://localhost:8181/cxf/crm' 
          - a list of service beans. in this example, we refer to another bean defined in this 
    		Blueprint XML file with a <ref/> element    -->
                          
       <jaxrs:server id="customerService" address="/crm">
           <jaxrs:serviceBeans>
               <ref component-id="customerSvc"/>
           </jaxrs:serviceBeans>
           <jaxrs:providers>
               <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
           </jaxrs:providers>
           <jaxrs:features>
    	      <bean class=“io.fabric8.cxf.endpoint.SwaggerFeature” />
    		   <property name=“title” value=“Fabric8:CXF:Quickstarts - Customer Service” />
    	   	<property name=“description” value=“Sample REST-based Customer Service” />
    		   <property name=“version” value=“${project.version}” />
    	      </bean>
           </jaxrs:features>
        </jaxrs:server>
      
    
        <!-- We use the OSGi Blueprint XML syntax to define a bean referred to in the 
        JAX-RS server setup. This bean carries a set of JAX-RS annotations that enable mapping 
        its methods to incoming requests.  -->
        
        <bean id="customerSvc" class="io.fabric8.quickstarts.rest.CustomerService"/>
    
    </blueprint>
  • In the REST resource class:

Building and Deploying the Rest quickstart

See the README file in your JBoss Fuse 6.2.1 installDir/quickstarts/cxf/rest/ directory for instructions on how to build and deploy the rest quickstart.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.