***************************
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. Cache和DMA一致性

    DMA应该多多少少知道点吧.DMA(Direct Memory Access)是指在外接可以不用CPU干预,直接把数据传输到内存的技术.这个过程中可以把CPU解放出来,可以很好的提升系统性能.那么DM ...

  2. kotlin集合——>集合操作概述、集合转换

    1. 集合操作概述: Kotlin 标准库提供了用于对集合执行操作的多种函数.这包括简单的操作,例如获取或添加元素,以及 更复杂的操作,包括搜索.排序.过滤.转换等 1.1 扩展与成员函数 集合操作在 ...

  3. kaggle数据集某咖啡店的营销数据分析

    因为还处于数据分析的学习阶段(野生Python学者),所以在kaggle这个网站找了两个数据集来给自己练练手. 准备工作 import pandas as pd import os import ma ...

  4. NIO和传统IO

    传统 IO 基于字节流或字符流(如 FileInputStream.BufferedReader 等)进行文件读写,以及使用 Socket 和 ServerSocket 进行网络传输. NIO 使用通 ...

  5. 文件操作(C语言)

    1. 为什么使用文件? 如果没有文件,我们写的程序的数据是存储在电脑的内存中,如果程序退出,内存回收,数据就丢失了,等再次运行程序,是看不到上次程序的数据的,如果要将数据进行持久化的保存,我们可以使用 ...

  6. shell脚本安装卸载统一脚本

    #!/bin/bash set -e OUT_DIR=out function usage() { cat - <<-EOF SlightShift-SPB Kit Usage: $0 & ...

  7. Python 提取PowerPoint文档中的图片

    如果你需要在多个PowerPoint演示文稿中使用相同的图片,直接从原始PPT中提取并保存图片可以避免重复寻找和下载.此外,将PPT中的重要图片提取出来可以将其作为备份,以防原文件损坏或丢失.本文将通 ...

  8. Python如何根据给定模型计算权值

    在机器学习和深度学习中,模型的权值(或参数)通常是通过训练过程(如梯度下降)来学习和调整的.然而,如果我们想根据一个已经训练好的模型来计算或提取其权值,Python 提供了许多工具和库,其中最常用的是 ...

  9. jmeter如何产生批量数据?

    在使用jmeter时,若需要产生批量数据,可以通过连接数据库--执行相关sql进行操作,例如添加20条数据 步骤: 1.添加jdbc 数据库配置信息 2.添加循环控制器(循环次数20) 3.循环控制器 ...

  10. Python模块之functools.partial

    在Python编程中,functools.partial是一个强大的工具,它提供了一种部分应用函数的方式,能够在创建新函数时固定部分参数,从而在后续调用中减少需要传递的参数数量.本文将深入介绍func ...