Spring Swagger在nginx 二级url 无法正常使用 修改host解决

Spring Swagger在nginx 二级url 无法正常使用 修改host解决

问题描述

测试环境用了nginx做二级url做映射,但swagger的 http://www.xxx.com/二级url/v2...
JSON里面的host地址还是一级目录,不自动对应nginx做了映射的二级url,因此使用swagger-ui.html在线调试API接口,就出问题,请求不到服务报404。

解决方法

配置直接设置Docke的host就可以了,网上搜索一堆完全没找到这个问题的解决方案,最后翻了源码找到host()方法。


application.yml

swagger:  host: www.xxx.com/二级url

Swagger配置类

@Configurationpublic class SwaggerConfig {    @Value("${swagger.host}")    private String swaggerHost;    @Bean    public Docket customDocket() {        Docket docket=new Docket(DocumentationType.SWAGGER_2);        if(StringUtils.isNotBlank(swaggerHost)){            docket=docket.host(swaggerHost);        }        docket=docket.apiInfo(apiInfo())                .useDefaultResponseMessages(false)                .select()                .apis(RequestHandlerSelectors.basePackage("com.xxx.xxx.web"))                .paths(PathSelectors.any())                .build();        return docket;    }    private ApiInfo apiInfo() {        return new ApiInfoBuilder()                .title("API接口文档")                .description("API接口文档")                .contact(new Contact("xx", "http:/xxx.com", "xxxx@qq.com"))                .version("1.0")                .build();    }}

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部