首页 文章

如何为swagger 2.8.0做友好的基本网址

提问于
浏览
2

我正在尝试更改API文档的基本访问URL . 网址是“http://localhost:8080/swagger-ui.html ". I want to get something like " http://localhost:8080/myapi/swagger-ui.html” .

我使用Springfox 2.8.0 Swagger,Java 8,Spring Boot 2.0 . 招摇配置是:

@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket api(ServletContext servletContext) {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathProvider(new RelativePathProvider(servletContext) {
                    @Override
                    public String getApplicationBasePath() {
                        return "/myapi";
                    }
                })
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(Predicates.not(PathSelectors.regex("/error")))
                .build()
                .useDefaultResponseMessages(false);
    }
}

自定义路径提供程序必须提供帮助,但我仍然可以使用URL“http://localhost:8080/swagger-ui.html ". If I use url " http://localhost:8080/myapi/swagger-ui.html”访问api文档,我收到404错误 . 请看下面的截图 .

enter image description here

1 回答

相关问题