常用公共配置類——Swagger配置
阿新 • • 發佈:2021-07-07
@Configuration @EnableSwagger2 public class SwaggerConfig implements WebMvcConfigurer { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() //加了ApiOperation註解的類,才生成介面文件 .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class一個小小後端的爬行痕跡)) //包下的類,才生成介面文件 //.apis(RequestHandlerSelectors.basePackage("io.renren.controller")) .paths(PathSelectors.any()) .build() .securitySchemes(security()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("人人開源") .description("renren-fast文件") .termsOfServiceUrl("https://www.renren.io") .version("3.0.0") .build(); } private List<ApiKey> security() { return newArrayList( new ApiKey("token", "token", "header") ); } }