news 2026/5/13 12:27:07

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

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
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

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/5/10 22:17:29

MS SQL Server 实战 排查多列之间的值是否重复

目录 需求 范例运行环境 数据样本设计 功能实现 上传EXCEL文件到数据库 SQL语句 小结 需求 在日常的应用中&#xff0c;排查列重复记录是经常遇到的一个问题&#xff0c;但某些需求下&#xff0c;需要我们排查一组列之间是否有重复值的情况。比如我们有一组题库数据&am…

作者头像 李华
网站建设 2026/5/12 5:09:31

2026免费好用的AIPPT工具榜:智能演示文稿制作新纪元

引言 随着人工智能技术的飞速发展&#xff0c;传统演示文稿的制作流程正经历一场深刻的变革。过去&#xff0c;制作一份专业的PPT往往意味着数小时乃至数天的内容构思、手动排版与视觉设计。如今&#xff0c;AI生成PPT工具的出现&#xff0c;正将这一过程简化为几分钟的智能交…

作者头像 李华
网站建设 2026/5/3 8:19:30

Python高效计算斐波那契数列

实现功能&#xff1a;计算斐波那契数列的第n项以下是用 Python 编写的递归方法实现斐波那契数列&#xff1a;def fibonacci(n):if n < 0:return "输入必须为正整数"elif n 1:return 0elif n 2:return 1else:return fibonacci(n - 1) fibonacci(n - 2)# 示例调用…

作者头像 李华