@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)) //包下的类,才生成接口文档 .paths(PathSelectors.any()) .build() .securitySchemes(security()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("XXXX后台管理") .description("接口文档") .build(); } private List<ApiKey> security() { return newArrayList( new ApiKey("token", "token", "header") ); } } 复制代码
配置完成后刷新页面则会显示
点击Authorize
填入你生成的token并按authorize则完成了全局的token校验问题,又能够愉快的联调了。