***************************
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. 世界第一!华为云图引擎服务GES大幅刷新世界纪录

    近日,国际关联数据基准委员会(Linked Data Benchmark Council,以下简称LDBC)公布了社交网络测试交互式负载(SNB INTERACTIVE WORKLOAD,以下简称为S ...

  2. NOI 2023 (简单题)

    Day1 T1 方格染色(color) 容易发现相对难处理的是斜线,但是我们发现斜线不超过 \(5\) 条,那么对于这一部分我们可以拆贡献,然后暴力做. 具体而言,先算出斜线减去横/竖线的面积,再算出 ...

  3. KubeSphere 社区双周报| 2024.08.16-08.29

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

  4. 图菱科技 SaaS 系统容器化最佳实践

    大家好,我是龚承明,在图菱(成都)科技有限公司任职,主要负责公司的产品系统研发以及公司IT基础设施的建设工作.本篇文章将为大家介绍下我司在采用 KubeSphere 平台实现公司业务系统容器化过程中的 ...

  5. 在C#中基于Semantic Kernel的检索增强生成(RAG)实践

    Semantic Kernel简介 玩过大语言模型(LLM)的都知道OpenAI,然后微软Azure也提供了OpenAI的服务:Azure OpenAI,只需要申请到API Key,就可以使用这些AI ...

  6. RabbitMQ3.8.16安装延迟队列插件

    安装过程 1:RabbitMQ 延迟插件GitHub 2:各版本地址 如我的MQ版本是3.8.16,那么根据提示下载的版本是: ①:移动插件到RabbitMQ的插件目录下,如我的位置是:/usr/li ...

  7. 【FAQ】HarmonyOS SDK 闭源开放能力 —IAP Kit(3)

    1.问题描述: 已经购买订阅型物品,未调用finishPurchase接口, 重新购买该物品,createPurchase接口返回的是001860001错误:System internal error ...

  8. php 对二维数组按照汉字首字母排序

    1 /** 2 * 取汉字的第一个字的首字母 3 * @param type $str 4 * @return string|null 5 */ 6 function _getFirstCharter ...

  9. SyncOOD:增加OOD目标检测鲁棒性,自动化数据助您一臂之力 | ECCV'24

    本文是对公开论文的核心提炼,而非直接翻译,旨在进行学术交流.如有任何侵权问题,请及时联系号主以便删除. 来源:晓飞的算法工程笔记 公众号,转载请注明出处 论文: Can OOD Object Dete ...

  10. 遗传算法+强化学习—TPG—Emergent Tangled Graph Representations for Atari Game Playing Agents_2

    最近在看进化算法在强化学习(RL)领域的一些应用,有些论文中将使用进化算法解决强化学习问题的算法归为非强化学习算法,然而又有些论文把使用进化算法解决强化学习问题的算法归为强化学习算法,不过更多的论文是 ...