我使用WildFly Swarm Project Generator创建了小型演示WildFly-Swarm休息应用程序 . 当我构建并运行我的应用程序时,如果转到http://localhost:8080/swagger,我会按预期得到我的Swagger.json:

{
   "swagger":"2.0",
   "info":{

   },
   "tags":[
      {
         "name":"hello"
      }
   ],
   "paths":{
      "/hello":{
         "get":{
            "tags":[
               "hello"
            ],
            "summary":"Just say hello...",
            "description":"Something",
            "operationId":"doGet",
            "produces":[
               "text/plain"
            ],
            "parameters":[

            ],
            "responses":{
               "200":{
                  "description":"successful operation",
                  "schema":{
                     "type":"string"
                  }
               }
            }
         }
      }
   }
}

但是当我去http://localhost:8080/swagger-ui时,我得到一个空页 . 我错过了一些配置,或者它应该开箱即用,没有额外的配置?

下面我附上了我的源码和pom.xml:

我的来源:

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

@Path("/hello")
@Api(value = "/hello", description = "Sey hello...")
public class HelloWorldEndpoint {

    @GET
    @Produces("text/plain")
    @ApiOperation(
            value = "Just say hello...",
            notes = "Something",
            response = String.class
    )
    public Response doGet() {
        return Response.ok("Hello from WildFly Swarm!").build();
    }
}

我的pom.xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>si.pucko</groupId>
    <artifactId>demo</artifactId>
    <name>WildFly Swarm Example</name>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <version.wildfly.swarm>2017.6.1</version.wildfly.swarm>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>bom-all</artifactId>
                <version>${version.wildfly.swarm}</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>demo</finalName>
        <plugins>
            <plugin>
                <groupId>org.wildfly.swarm</groupId>
                <artifactId>wildfly-swarm-plugin</artifactId>
                <version>${version.wildfly.swarm}</version>

                <executions>
                    <execution>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- Java EE 7 dependency -->
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!-- WildFly Swarm Fractions -->
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>jaxrs-jaxb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>swagger</artifactId>
        </dependency>
        <dependency>
            <groupId>org.wildfly.swarm</groupId>
            <artifactId>swagger-webapp</artifactId>
        </dependency>
    </dependencies>
</project>