zoukankan      html  css  js  c++  java
  • 解决访问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;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.service.Contact;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import 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() {
            return new ApiInfoBuilder().title("这是我的接口文档")
                    .contact(new Contact("rongrong", "", "emai@qq.com"))
                    .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();
        }
    }

      重启服务:再次访问如下

  • 相关阅读:
    03、CPU主频,和性能
    02、计算机组成原理相关知识
    常用正则表达式,手机号、固话号、身份证号等
    01、计算机原理结构,及冯诺依曼体系结构
    7-7 Complete Binary Search Tree (30分) 完全二叉搜索树
    7-2 Reversing Linked List (25分)
    7-1 Maximum Subsequence Sum (25分)
    6-17 Shortest Path [4] (25分)
    6-16 Shortest Path [3] (25分)
    6-15 Iterative Mergesort (25分)
  • 原文地址:https://www.cnblogs.com/longronglang/p/9045559.html
Copyright © 2011-2022 走看看