Profile Config 多环境不同配置

应用场景如:我们可以在开发、测试环境中,启用 Swagger,在生产环境中不启用

 只有 application.yml 中配 dev、test 的时候才启用

spring:
  profiles:
    active: dev

 

 

package com.vipsoft.web.boot.config;

import springfox.documentation.service.Contact;
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.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
@Profile({"dev","test"})
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.vipsoft.model.user.controller"))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo());
    }

    //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("SpringBoot整合Swagger")
                .description("SpringBoot整合Swagger,API接口描述......")
                .version("9.0")
                .contact(new Contact("VipSoft","www.vipsoft.com.cn","47262947@qq.com"))
                .license("The Apache License")
                .licenseUrl("http://www.baidu.com")
                .build();
    }
}

SpringBoot 配置 Swagger

posted @ 2022-01-20 16:09  VipSoft  阅读(131)  评论(0编辑  收藏  举报