Swaggers2是一款能够自动生成api文档的工具,非常好用,极大减小工作量。
1.引入pom.xml依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
2.创建配置文件:Swagger2Config.java
package com.shixin.config;
/**
* @Description Swagger2的相关配置
* @Author shixin
* @Date 2021/6/23 9:02
*/
@Configuration
public class Swagger2Config {
//默认访问地址:http://localhost:port/swagger-ui.html
//Swagger2核心配置:docket
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2) //指定api类型为swagger2
.apiInfo(apiInfo()) //定义api文档配置信息
.select().apis(RequestHandlerSelectors.basePackage("com.shixin.controller")) //指定需要扫描的controller包