The method's class, springfox.documentation.builders.RequestHandlerSelectors, is available from the following locations:
***************************
APPLICATION FAILED TO START
*************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: com.be.common.web.configurer.SwaggerConfigurer.docket(SwaggerConfigurer.java:51) The following method did not exist: springfox.documentation.builders.RequestHandlerSelectors.basePackage(Ljava/lang/String;)Lcom/google/common/base/Predicate; The method's class, springfox.documentation.builders.RequestHandlerSelectors, is available from the following locations: jar:file:/Users/u/.m2/repository/io/springfox/springfox-core/3.0.0/springfox-core-3.0.0.jar!/springfox/documentation/builders/RequestHandlerSelectors.class It was loaded from the following location: file:/Users/u/.m2/repository/io/springfox/springfox-core/3.0.0/springfox-core-3.0.0.jar Action: Correct the classpath of your application so that it contains a single, compatible version of springfox.documentation.builders.RequestHandlerSelectors
原因是可能重复配置swagger,可能是其他框架配置swagger了,只需要把框架内置的swagger配置禁用。
然后手动配置下knife4j 就可以了
package com.x.serving.core.config; import com.x.serving.annotation.SwaggerApi;
import com.x.serving.common.constants.ServingConstants;
import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; /**
* @author x
* @version 1.0.0
* @email <a href="x.x@x.cn">muzhi</a>
* @date 2022-02-14 15:19
*/
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class Swagger2Configuration implements WebMvcConfigurer {
@Override
public void addViewControllers(final ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("doc.html");
} /**
*
* 显示swagger-ui.html文档展示页,还必须注入swagger资源:
*
* @param registry
*/
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
} /**
* swagger2的配置文件,这里可以配置swagger2的一些基本的内容,比如扫描的包等等
*
* @return Docket
*/
@Bean(value = "defaultApi2")
public Docket defaultApi2() { // List<ResponseMessage> responseMessages = new ArrayList<>(2);
// ResponseMessage build = new ResponseMessageBuilder().code(200)
// .message("").responseModel(new ModelRef(Response.class.getName()))
// .build();
//
// responseMessages.add(build); return new Docket(DocumentationType.SWAGGER_2)
// .globalResponseMessage(RequestMethod.GET, responseMessages)
// .globalResponseMessage(RequestMethod.POST, responseMessages)
.apiInfo(apiInfo())
.select()
//此包路径下的类,才生成接口文档
.apis(RequestHandlerSelectors.basePackage("com.be.edge.serving")
.or(RequestHandlerSelectors.withClassAnnotation(SwaggerApi.class)))
//加了ApiOperation注解的类,才生成接口文档
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build()
.securitySchemes(Collections.singletonList(securityScheme()))
.securityContexts(securityContexts());
//.globalOperationParameters(setHeaderToken());
} /***
* oauth2配置
* 需要增加swagger授权回调地址
* http://localhost:8888/webjars/springfox-swagger-ui/o2c.html
* @return
*/
@Bean
SecurityScheme securityScheme() {
return new ApiKey(ServingConstants.TOKEN_NAME, ServingConstants.TOKEN_NAME, "header");
}
/**
* JWT token
* @return
*/
private List<Parameter> setHeaderToken() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
tokenPar.name(ServingConstants.TOKEN_NAME).description(ServingConstants.TOKEN_DESCRIPTION).modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
return pars;
} /**
* api文档的详细信息函数,注意这里的注解引用的是哪个
*
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
// //大标题
.title("EdgeX-Lambda 后台服务API接口文档")
// 版本号
.version("1.0")
// .termsOfServiceUrl("NO terms of service")
// 描述
.description("后台API接口")
// 作者
.contact(new Contact("牧之", "http://localhost:6500/", "email@mail.com"))
.license("The Apache License, Version 2.0")
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.build();
} /**
* 新增 securityContexts 保持登录状态
*/
private List<SecurityContext> securityContexts() {
return new ArrayList(
Collections.singleton(SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex("^(?!auth).*$"))
.build())
);
} private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return new ArrayList(
Collections.singleton(new SecurityReference(ServingConstants.TOKEN_NAME, authorizationScopes)));
}
}
#swagger
knife4j:
#开启增强配置
enable: true
#开启生产环境屏蔽
production: false
The method's class, springfox.documentation.builders.RequestHandlerSelectors, is available from the following locations:的更多相关文章
- springfox.documentation.spi.DocumentationType配置示例
Java Code Examples for springfox.documentation.spi.DocumentationType The following are top voted exa ...
- springfox.documentation.service.ApiInfo配置示例
Java Code Examples for springfox.documentation.service.ApiInfo The following are top voted examples ...
- Springfox Reference Documentation
1. Introduction The Springfox suite of java libraries are all about automating the generation of mac ...
- SpringBoot中使用springfox+swagger2书写API文档
随着前后端的分离,借口文档变的尤其重要,springfox是通过注解的形式自动生成API文档,利用它,可以很方便的书写restful API,swagger主要用于展示springfox生成的API文 ...
- Maven+SpringMVC+SpringFox+Swagger整合示例
查考链接:https://my.oschina.net/wangmengjun/blog/907679 coding地址:https://git.coding.net/conding_hjy/Spri ...
- 一步步完成Maven+SpringMVC+SpringFox+Swagger整合示例
本文给出一个整合Maven+SpringMVC+SpringFOX+Swagger的示例,并且一步步给出完成步骤. 本人在做实例时发现 http://blog.csdn.net/zth1002/art ...
- SpringMVC、SpringFox和Swagger整合项目实例
目标 在做项目的时候,有时候需要提供其它平台(如业务平台)相关的HTTP接口,业务平台则通过开放的HTTP接口获取相关的内容,并完成自身业务~ 提供对外开放HTTP API接口,比较常用的是采用Spr ...
- SpringMVC整合SpringFox实践总结
项目中使用的swagger框架在生成api文档时存在一些问题: 1. 控制器下方法无法点击展开 2.api内容结构混乱 基于上述原因,重新整合重构了一下api文档生成的代码.在此将重整过程记录下来,方 ...
- MP实战系列(十)之SpringMVC集成SpringFox+Swagger2
该示例基于之前的实战系列,如果公司框架是使用JDK7以上及其Spring+MyBatis+SpringMVC/Spring+MyBatis Plus+SpringMVC可直接参考该实例. 不过建议最好 ...
- spring cloud 学习(10) - 利用springfox集成swagger
对绝大多数程序员而言,写接口文档是一件痛苦的事情,相对文档,他们更愿意写代码.最理想的情况就是:代码即文档!服务开发完成后,部署上去文档就自动生成,没错,这就是springfox + swagger要 ...
随机推荐
- 使用LayUI实现文件上传的一个误区
1.HTML 2.JS 3.后端处理(注意:参数 file) 这里传入的参数名只能是 file LayUI文件上传官方文档: https://www.layui.com/doc/modules/upl ...
- RecyclerView刷新方式
RecyclerView刷新方式 刷新全部item notifyDataSetChanged() student.setValue(new Student("二狗")); stud ...
- 掀起云端革命!ToDesk云电脑与传统PC电脑的差异分析
在科技日新月异的今天,传统PC电脑的市场地位正悄然发生变化.随着云计算技术的不断成熟与普及,云电脑逐渐走进大众视野,不同于传统PC电脑的高昂的成本和易退化的硬件性能,云电脑正以其轻成本高性能的优势吸引 ...
- 彻底搞懂ScheduledThreadPoolExecutor
前言 项目中经常会遇到一些非分布式的调度任务,需要在未来的某个时刻周期性执行.实现这样的功能,我们有多种方式可以选择: Timer类, jdk1.3引入,不推荐. 它所有任务都是串行执行的,同一时间只 ...
- dotnet core微服务框架Jimu ~ 会员授权微服务
提供授权服务,用户使用会员的用户名和密码获取 token, 带着 token 访问受保护的接口,如浏览和发布新闻. 有 2 个公开的 api: token: 获取 token; GetCurrentM ...
- 题解:「NOIP2022 提高组」种花
题解:「NOIP2022 提高组」种花 题目大意:给定一个 \(n \times m\) 的01矩阵,0表示可以种花,1表示土坑(无法种花),现在要在图上种出一个C型或F型(C,F横着的两条线的长度都 ...
- centos7-arm架构yum源(armhf) yum源(中国科学技术大学)
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # upda ...
- 腾讯AICR : 智能化代码评审技术探索与应用实践(下)
- app&小程序&web安全—sign签名绕过
零.前言 在web界面登陆时,小程序和app传输数据时经常会碰到签名,会对请求的参数进行签名,如果自己修改了数据包就会校验失败非常麻烦. 本文编写的契机就是因为碰到了一个JeecgBoot的小程序, ...
- [昌哥IT课堂]|ubuntu18.04手动安装mysql8.0.33 deb包
前期准备 1.更新aliyun的软件包安装源: 手动更改 用你熟悉的编辑器打开: /etc/apt/sources.list 把源来链接删除或注释: 加入以下命令: ubuntu 18.04 LTS ...