微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

解决访问swaggerUI接口文档显示basic-error-controler问题

问题描述

使用swagger生成接口文档后,访问http://localhost:8888/swagger-ui.html#/,显示如下:

有些强迫症的我,感觉看起来很不舒服,结果百度了好久,找到解决方案,刚接触spring boot对于很多api还不是很熟悉,先mark再说

代码如下:

package com.course.config;

import com.google.common.base.Predicates;
 org.springframework.context.annotation.Bean;
 org.springframework.context.annotation.Configuration;
 springfox.documentation.builders.ApiInfoBuilder;
 springfox.documentation.builders.PathSelectors;
 springfox.documentation.builders.RequestHandlerSelectors;
 springfox.documentation.service.ApiInfo;
 springfox.documentation.service.Contact;
 springfox.documentation.spi.DocumentationType;
 springfox.documentation.spring.web.plugins.Docket;
 springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @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() {
        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();
    }
}

 

  重启服务:再次访问如下

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐