spring boot配置Swagger2

创建common模块 (新建MAVEN模块)

 由于后面多个模块会使用到Swagger 所以我们把Swagger的配置写在common模块中

2、在common中引入Swagger相关依赖

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.7.0</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.7.0</version>
</dependency>

3、在common下面创建子模块service-base

创建包com.atguigu.servicebase.config,创建类SwaggerConfig

@Configuration//配置类
@EnableSwagger2 //开启Swagger
public class SwaggerConfig {
    @Bean
    public Docket webApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                /*.paths(Predicates.not(PathSelectors.regex("/admin/.*")))*/
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();
    }

    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("网站-课程中心API文档")
                .description("本文档描述了课程中心微服务接口定义")
                .version("1.0")
                .contact(new Contact("Helen", "http://atguigu.com", "55317332@qq.com"))
                .build();
    }
}

4、在模块service模块中引入service-base

<dependency>
    <groupId>com.atguigu</groupId>
    <artifactId>service-base</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

5、在service-edu启动类上添加注解

因为我们需要扫描其他模块的配置 所以我们在edu启动类上加注解 扫描所有com.atguigi下的配置类

原文地址:https://www.cnblogs.com/fxzemmm/p/14418154.html