swagger2.9.2配置使用
①环境:
- SpringBoot2.3.4.RELEASE
- jdk11
②依赖:
<!--swagger-->
<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>
③配置类:
package com.atguigu.bookcity.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
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;
import java.util.ArrayList;
/**
* @author ycjstart
* @create 2022-11-16 15:56
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()// 通过.select()方法,去配置扫描接口,RequestHandlerSelectors配置如何扫描接口
.apis(RequestHandlerSelectors.basePackage("com.atguigu.bookcity.controller"))
.build();
}
//配置文档信息
private ApiInfo apiInfo() {
Contact contact = new Contact("YangChengJun", "https://gitee.com/ycjstart", "2213782670@qq.com");
return new ApiInfo(
"book-city", // 标题
"book-city单体应用", // 描述
"v1.0", // 版本
"https://gitee.com/ycjstart", // 组织链接
contact, // 联系人信息
"Apach 2.0 许可", // 许可
"许可链接", // 许可连接
new ArrayList<>()// 扩展
);
}
}

浙公网安备 33010602011771号