SpringBoot整合Swagger2一直弹窗的坑

SpringBoot整合Swagger2一直弹窗的坑

问题现象:

我的Swagger配置信息文件如下

package com.qbb.qmall.service.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.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;/** * @author QiuQiu&LL (个人博客:https://www.cnblogs.com/qbbit) * @version 1.0 * @date 2022-05-18  16:30 * @Description: */@Configuration@EnableSwagger2public class Swagger2Config {    @Bean    public Docket adminApiConfig() {        return new Docket(DocumentationType.SWAGGER_2)                .groupName("adminApi")                .apiInfo(adminApiInfo())                .select()                //只显示admin路径下的页面                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))                .build();    }    private ApiInfo adminApiInfo() {        return new ApiInfoBuilder()                .title("SPH后台管理系统-API文档")                .description("本文档描述了SPH后台管理系统接口")                .version("1.0")                .contact(new Contact("QIUQIU&LL", "https://www.cnblogs.com/qbbit", "startqbb@163.com"))                .build();    }    @Bean    public Docket apiConfig() {        return new Docket(DocumentationType.SWAGGER_2)                .groupName("api")                .apiInfo(apiInfo())                .select()                //只显示admin路径下的页面                .paths(Predicates.and(PathSelectors.regex("/api/.*")))                .build();    }    private ApiInfo apiInfo() {        return new ApiInfoBuilder()                .title("SPH-API文档")                .description("本文档描述了SPH接口")                .version("1.0")                .contact(new Contact("QIUQIU&LL", "https://www.cnblogs.com/qbbit", "startqbb@163.com"))                .build();    }}

解决办法:

  • 由于我是分模块开发,所以我所写的配置文件相关微服务的主启动并没有扫描到...所以swagger一直弹窗
    在主启动类上加入@ComponentScan("项目公共路径") 或者 @Import(Swagger2Config.class)

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