使用方法一:官方方法
- 添加依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
- 添加配置类
什么都不写的话,使用默认配置,详细的配置在swagger官方推荐方法的配置类简解
package com.example.swagger.config;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
}
使用方法二:第三方工具类
- 添加依赖
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
- 在Spring Boot项目的启动类上添加
@EnableSwagger2Doc
注解,就可以直接使用。 GitHub上这个swagger依赖实现的项目,里面有详细的讲解。
访问路径为http://localhost:8080/swagger-ui.html