SpringBoot 整合 Swagger3.0
- 引入 Swagger3 依赖
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
- 配置
@Configuration
@EnableOpenApi
public class SwaggerConfig {
@Bean
public Docket docket(){
return new Docket(DocumentationType.OAS_30)
.apiInfo(apiInfo())
.enable(true)
.select()
.apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo(){
return new ApiInfoBuilder()
.title("XX项目接口文档")
.description("XX项目描述")
.contact(new Contact("作者", "作者URL", "作者Email"))
.version("1.0")
.build();
}
}
- 使用
@Api(tags="用户管理")
@RestController
public class UserController {
@ApiOperation("用户信息")
@GetMapping("/test")
public User test() {
return new User();
}
}
- 测试
/swagger-ui/index.html
/swagger-resources
权限控制需过滤路径:
/swagger**/** /v3/** ...