Loading

SpringBoot 整合 Swagger3.0

  1. 引入 Swagger3 依赖
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>
  1. 配置
@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();
    }
}
  1. 使用
@Api(tags="用户管理")
@RestController
public class UserController {

    @ApiOperation("用户信息")
    @GetMapping("/test")
    public User test() {
        return new User();
    }
}
  1. 测试

/swagger-ui/index.html

/swagger-resources

权限控制需过滤路径:

/swagger**/**
/v3/**
...
posted @ 2021-05-10 18:00  LB477  阅读(119)  评论(0编辑  收藏  举报