springboot 使用swagger 不显示basic-error-controller解决

在启动类的主类下加入如下代码,


`/* 配置 swagger开始 /
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).pathMapping(“/”).select() // 选择那些路径和api会生成document
.apis(RequestHandlerSelectors.any())// 对所有api进行监控
// 不显示错误的接口地址
.paths(Predicates.not(PathSelectors.regex(“/error.*”)))// 错误路径不监控
.paths(PathSelectors.regex(“/.*”))// 对根下所有路径进行监控
.build();
}

private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("产品接口文档")
            // .contact(new Contact("rongrong", "", "[email protected]"))
            // .description("这是SWAGGER_2生成的接口文档")
            // .termsOfServiceUrl("NO terms of service")
            // .license("The Apache License, Version 2.0")
            // .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
            // .version("v1.0")
            .build();
}`

再次启动访问http://localhost:9090/swagger-ui.html#/
就可以看到结果了

猜你喜欢

转载自blog.csdn.net/m0_37948170/article/details/80834718