apacherestcxfswaggerswagger-ui

How to integrate swagger tool with apache CXF REST web service using CXFNonSpringJaxrsServlet?


Could you please someone provide the clear steps to integrate with Swagger into Apache CXF JAX-RS application without spring framework support(using using org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet).

I have gone through swagger site and blogs I haven't find any clear steps for configuring swagger.


Solution

  • I did these steps:

    1. Added required dependency to my project:

          <!-- SWAGGER -->
          <dependency>
              <groupId>io.swagger</groupId>
              <artifactId>swagger-jaxrs</artifactId>
              <version>1.5.8</version>
          </dependency>
          <dependency>
              <groupId>org.webjars</groupId>
              <artifactId>swagger-ui</artifactId>
              <version>2.1.4</version>
              <scope>provided</scope>
          </dependency>
          <dependency>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-api</artifactId>
              <version>${slf4j-simple.version}</version>
          </dependency>
          <dependency>
              <groupId>org.slf4j</groupId>
              <artifactId>slf4j-simple</artifactId>
              <version>${slf4j-simple.version}</version>
          </dependency>
      
    2. Updated the web.xml as mentioned here: https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61318164

    3. Added swagger-ui 2.1.4 as project resources (I edited index.html to point at the right url);

    4. Added @Api annotation to my services cxf;

    Hopes this help

    UPDATE:

    CXF dependency:

        <!-- CXF -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxrs</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-rs-service-description</artifactId>
            <version>${cxf.version}</version>
        </dependency>
    

    with cxf.version = 3.1.5 (CXF 3.1.X is only for jdk 1.7 or newer)