如何访问Swagger文档

问题描述

我有一个带有REST服务的Java应用程序,我想用Swagger进行记录,因此我正在关注this教程。

我有以下内容:

MyRestApplication.java

@ApplicationPath("rest")
public class MyRestApplication extends Application
{

    /**
     * Set the Swagger access
     */
    public TravellinckRestApplication() {
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.0");
        beanConfig.setTitle("NexCT API");
        beanConfig.setSchemes(new String[]{"https"});
        beanConfig.setHost("localhost:8443");
        beanConfig.setBasePath("/corporateInterface/rest");
//        beanConfig.setResourcePackage("io.swagger.resources");
        beanConfig.setResourcePackage("com.nexct");
        beanConfig.setScan(true);
    }

    @Override
    public Set<Class<?>> getClasses()
    {
        Set<Class<?>> resourceClasses = new HashSet<Class<?>>();

        // Resources / Endpoints

        resourceClasses.add(io.swagger.jaxrs.listing.ApiListingResource.class);
        resourceClasses.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);

        return  resourceClasses;
    }
}

pom.xml

        <plugin>
            <groupId>com.googlecode.maven-download-plugin</groupId>
            <artifactId>download-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>swagger-ui</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>wget</goal>
                    </goals>
                    <configuration>
                        <skipCache>false</skipCache>
                        <url>https://github.com/swagger-api/swagger-ui/archive/master.tar.gz</url>
                        <unpack>true</unpack>
                        <outputDirectory>${project.build.directory}</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy-resources</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/${build.finalName}/docs</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${project.build.directory}/swagger-ui-master/dist</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <version>1.5.3</version>
            <artifactId>replacer</artifactId>
            <executions>
                <execution>
                    <id>replace-swagger-json-location</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>replace</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <file>${project.build.directory}/corporateInterface/docs/index.html</file>
                <replacements>
                    <replacement>
                        <token>https://petstore.swagger.io/v2/swagger.json</token>
                        <value>/corporateInterface/api/swagger.json</value>
                    </replacement>
                </replacements>
            </configuration>
        </plugin>

然后我运行:

mvn clean install -DskipTests;

并将生成的EAR文件复制到jboss-as-7.0.2.Final/standalone/deployments文件夹中。

现在我可以访问:

https:// localhost:8443 / corporateInterface / rest / swagger.json

{"swagger":"2.0","info":{"version":"1.0.0","title":"NexCT API"},"host":"localhost:8443","basePath":"/corporateInterface/rest","schemes":["https"]}

问题

如何访问Swagger文档?

例如https://localhost:8443/corporateInterface/rest/docs返回404

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...