• 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下的配置类

  • 相关阅读:
    教你玩转CSS的所有字体,路过的来瞧一瞧。
    CSS基本语法?
    怎么样才能玩转前端所有的CSS背景相关问题?
    如何玩转CSS内部样式表与外部样式表?
    什么是CSS?你真的理解了吗?
    CSS页面demo
    HTML教程(看完这篇就够了)
    HTML5新增的主体结构元素
    Math
    练习点菜及用的公式
  • 原文地址:https://www.cnblogs.com/fxzemmm/p/14418154.html
Copyright © 2020-2023  润新知