springboot集成swagger2
第一步:导入依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- swagger RESTful API -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.14</version>
<scope>provided</scope>
</dependency>
第二步:创建一个SwaggerConfig配置类
/**
* @author 杨明书
* @EnableSwagger2 开启swagger2
* @Date 2021/09/01 16:25
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
/**
* 配置多个分组
*/
@Bean
public Docket docket1(){
return new Docket(DocumentationType.SWAGGER_2).groupName("张三");
}
@Bean
public Docket docket2(){
return new Docket(DocumentationType.SWAGGER_2).groupName("李白");
}
@Bean
public Docket docket3(){
return new Docket(DocumentationType.SWAGGER_2).groupName("王舞");
}
@Bean
public Docket docket(Environment environment){
//设置需要显示的swagger环境
Profiles profiles=Profiles.of("dev","prod");
//获取项目环境 ,判断是否存在自己需要的环境
boolean flag = environment.acceptsProfiles(profiles);
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("杨明书")
//