1) 引入Swagger2和swagger ui (在父工程中依赖)
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> |
2) 编写配置类(@EnableSwagger2 开启swagger2自动生成api文档功能)
package com.atguigu.user.config;
import org.springframework.context.annotation.Configuration; import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2 //开启swagger2自动生成api文档的功能 @Configuration public class AppSwaggerConfig {
} |
http://localhost:8080/swagger-ui.html