当前位置: 首页 > news >正文

knife4j+springboot3.4异常无法正确展示文档

场景复现:

  • knife4j-openapi3-jakarta-spring-boot-starter版本

    com.github.xiaoymin knife4j-openapi3-jakarta-spring-boot-starter 4.5.0
  • 原来使用springboot3.3.5版本,先升级到3.4.0版本

  • 通过http://ip:port/doc.html访问接口文档发现访问/v3/api-docs接口时报

    Handler dispatch failed: java.lang.NoSuchMethodError: 'void org.springframework.web.method.ControllerAdviceBean.(java.lang.Object)

通过分析异常日志发现是ControllerAdviceBean类报错,在springboot3.3.5时spring-web版本是6.1.14,springboot3.4版本是6.2.0版本。

通过springboot全局异常捕获堆栈信息发现:

org.springdoc.core.service.GenericResponseService.lambda$getGenericMapResponse$8(GenericResponseService.java:702)

GenericResponseService类是在如下包:

<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-common --> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-common</artifactId> <version>2.3.0</version> </dependency>

GenericResponseService类的702行代码如下(ControllerAdviceBean类使用一个参数的构造函数,但是报异常):

List<ControllerAdviceInfo> controllerAdviceInfosNotInThisBean = controllerAdviceInfos.stream() .filter(controllerAdviceInfo -> new ControllerAdviceBean(controllerAdviceInfo.getControllerAdvice()).isApplicableToBeanType(beanType)) .filter(controllerAdviceInfo -> !beanType.equals(controllerAdviceInfo.getControllerAdvice().getClass())) .toList();

spring-web6.1.14版本中ControllerAdviceBean的构造函数:

public ControllerAdviceBean(Object bean) { Assert.notNull(bean, "Bean must not be null"); this.beanOrName = bean; this.isSingleton = true; this.resolvedBean = bean; this.beanType = ClassUtils.getUserClass(bean.getClass()); this.beanTypePredicate = createBeanTypePredicate(this.beanType); this.beanFactory = null; }

spring-web6.2.0版本中ControllerAdviceBean的构造函数:

public ControllerAdviceBean(String beanName, BeanFactory beanFactory, ControllerAdvice controllerAdvice) { Assert.hasText(beanName, "Bean name must contain text"); Assert.notNull(beanFactory, "BeanFactory must not be null"); Assert.isTrue(beanFactory.containsBean(beanName), () -> "BeanFactory [" + beanFactory + "] does not contain specified controller advice bean '" + beanName + "'"); Assert.notNull(controllerAdvice, "ControllerAdvice must not be null"); this.beanName = beanName; this.isSingleton = beanFactory.isSingleton(beanName); this.beanType = getBeanType(beanName, beanFactory); this.beanTypePredicate = createBeanTypePredicate(controllerAdvice); this.beanFactory = beanFactory; }

此类中的构造函数已经变更为4个,已经不存在一个参数的构造函数了。

  • springdoc-openapi-starter-common文档当前已经升级到2.7.0版本

    org.springdoc springdoc-openapi-starter-common 2.7.0

结论:期待knife4j-openapi3-jakarta-spring-boot-starter早日升级,兼容最新版本的spring;

开源SDK:https://github.com/mingyang66/spring-parent

http://www.jsqmd.com/news/212093/

相关文章:

  • 深度学习计算机毕设之基于深度学习的土豆疾病识别卷神经网络
  • LangChain-09 Query SQL DB With RUN GPT 查询数据库 并 执行SQL 返回结果
  • Python高效计算斐波那契数列
  • AWS OpenSearch Service TLS 策略升级指南
  • 深度学习毕设项目:基于人工智能深度学习的土豆疾病识别
  • LangChain-08 Query SQL DB 通过GPT自动查询SQL
  • 使用dify搭建爬虫Agent工作流
  • 【课程设计/毕业设计】基于深度学习机器学习的土豆疾病识别
  • 内驱力:点燃自我成长的发动机
  • Katalon平台的集成生态
  • Python代码实现示例解析
  • 深度学习毕设项目:基于python深度学习的苹果和西红柿识别
  • 新手进阶Python:给办公助手加定时功能,自动处理任务不用盯
  • FastAPI 极简教程1
  • 计及电转气协同的含碳捕集与垃圾焚烧虚拟电厂优化调度Matlab代码
  • 数据科学为大数据领域的业务增长赋能
  • 深度学习毕设选题推荐:python基于CNN卷积神经网络对猫狗数据集训练识别
  • 精准编程代码生成指南
  • 基于阶梯碳交易的含P2G-CCS耦合和燃气掺氢的虚拟电厂优化调度Matlab代码
  • 什么是LLDP
  • 深度学习毕设选题推荐:基于python-cnn深度学习的猫的种类识别基于人工智能-cnn深度学习的猫的种类识别
  • 华为OD技术面真题 - 计算机网络 - 1
  • 基于氢储能的热电联供型微电网优化调度方法Matlab代码
  • 编程实战:从原理到代码的完整指南
  • 深度学习毕设选题推荐:基于 python深度学习的罗马数据集训练识别人工智能
  • 深入解析HMAC:消息认证码的核心原理
  • 深度测评8个一键生成论文工具,专科生毕业论文轻松搞定!
  • iir滤波器的理论分析与matlab仿真,对比butter/cheby1/cheby2/ellip/yulewalk
  • java进阶--多线程学习
  • Java进阶教程(一)关键字