***************************
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:的更多相关文章

  1. springfox.documentation.spi.DocumentationType配置示例

    Java Code Examples for springfox.documentation.spi.DocumentationType The following are top voted exa ...

  2. springfox.documentation.service.ApiInfo配置示例

    Java Code Examples for springfox.documentation.service.ApiInfo The following are top voted examples ...

  3. Springfox Reference Documentation

    1. Introduction The Springfox suite of java libraries are all about automating the generation of mac ...

  4. SpringBoot中使用springfox+swagger2书写API文档

    随着前后端的分离,借口文档变的尤其重要,springfox是通过注解的形式自动生成API文档,利用它,可以很方便的书写restful API,swagger主要用于展示springfox生成的API文 ...

  5. Maven+SpringMVC+SpringFox+Swagger整合示例

    查考链接:https://my.oschina.net/wangmengjun/blog/907679 coding地址:https://git.coding.net/conding_hjy/Spri ...

  6. 一步步完成Maven+SpringMVC+SpringFox+Swagger整合示例

    本文给出一个整合Maven+SpringMVC+SpringFOX+Swagger的示例,并且一步步给出完成步骤. 本人在做实例时发现 http://blog.csdn.net/zth1002/art ...

  7. SpringMVC、SpringFox和Swagger整合项目实例

    目标 在做项目的时候,有时候需要提供其它平台(如业务平台)相关的HTTP接口,业务平台则通过开放的HTTP接口获取相关的内容,并完成自身业务~ 提供对外开放HTTP API接口,比较常用的是采用Spr ...

  8. SpringMVC整合SpringFox实践总结

    项目中使用的swagger框架在生成api文档时存在一些问题: 1. 控制器下方法无法点击展开 2.api内容结构混乱 基于上述原因,重新整合重构了一下api文档生成的代码.在此将重整过程记录下来,方 ...

  9. MP实战系列(十)之SpringMVC集成SpringFox+Swagger2

    该示例基于之前的实战系列,如果公司框架是使用JDK7以上及其Spring+MyBatis+SpringMVC/Spring+MyBatis Plus+SpringMVC可直接参考该实例. 不过建议最好 ...

  10. spring cloud 学习(10) - 利用springfox集成swagger

    对绝大多数程序员而言,写接口文档是一件痛苦的事情,相对文档,他们更愿意写代码.最理想的情况就是:代码即文档!服务开发完成后,部署上去文档就自动生成,没错,这就是springfox + swagger要 ...

随机推荐

  1. C# webapi 跨域

    #region 启用跨域访问 app.UseCors(builder => builder .AllowAnyMethod() .SetIsOriginAllowed(_ => true) ...

  2. KubeSphere 社区双周报|2024.03.15-03.29

    KubeSphere 社区双周报主要整理展示新增的贡献者名单和证书.新增的讲师证书以及两周内提交过 commit 的贡献者,并对近期重要的 PR 进行解析,同时还包含了线上/线下活动和布道推广等一系列 ...

  3. 在 Azure CNI 中启用 Calico WireGuard

    作者:Peter Kelly 译者:Wendi Wang 注:本文已取得作者本人的翻译授权! 去年6月,Tigera 宣布首次在 K8s 上支持用于集群内加密传输的开源 VPN - WireGuard ...

  4. 基于BIO的Socket通信

    基于BIO的Socket通信 告知对方命令发送完毕 关闭socket:socket.close() 关闭流:socket.shutdownOutput(),ocket.shutdownInput() ...

  5. typescript 编译报错 不能用于索引类型

    Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 't ...

  6. SQL Server 数据太多如何优化

    大家好,我是 V 哥.讲了很多数据库,有小伙伴说,SQL Server 也讲一讲啊,好吧,V 哥做个听话的门童,今天要聊一聊 SQL Server. 在 SQL Server 中,当数据量增大时,数据 ...

  7. games101_Homework2

    完成函数static bool insideTriangle(): 测试点是否在三角形内. 一段优雅的easy代码,没什么好说的.(但是需要修改这里传入的xy的类型为float,默认为int是想让我通 ...

  8. aiflow部署文档

    aiflow部署文档 一.简介 本文档用来进行aiflow项目的完全部署 二.安装环境 2.1 安装系统镜像版本 使用Centos镜像文件:CentOS-7-x86_64-DVD-1908.iso c ...

  9. FreeRTOS LIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 存在的意义以及高于它的中断不能调用 safe freertos api

    This is how I understand it. 我是这样理解的. If we now have 2 tasks and 6 interrupts, among which, and when ...

  10. 重新使用Java的七个理由

    译者注:此文系作者于2011年7月11发表于OnJava O'Reily正在庆祝Java7的发布,以及7月25日到27日即将在波兰开展的 OSCON Java 大会. Java宣告回归了,同胞们.当然 ...