您的位置:首页 > 编程语言 > Java开发

SpringBoot整合Swagger2一直弹窗的坑

2022-05-19 13:24 1726 查看

问题现象:

我的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
@EnableSwagger2
public 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)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: