news 2026/7/28 0:42:50

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/7/19 14:22:01

LeetCode 172. Factorial Trailing Zeroes 题解

题目概述 LeetCode 172. Factorial Trailing Zeroes&#xff1a;给定一个整数 n&#xff0c;返回 n! 中尾随零&#xff08;结尾连续的 0&#xff09;的个数。leetcode​ 注意&#xff1a; n! n (n − 1) … 2 10 ≤ n ≤ 10^4Follow up&#xff1a;是否可以在对数时间复…

作者头像 李华
网站建设 2026/7/22 0:41:30

AWS OpenSearch Service TLS 策略升级指南

📋 概述 AWS OpenSearch Service 将于 2026 年 4 月 20 日停止支持 TLS 1.0 和 1.1 版本。本文详细介绍如何安全地将 OpenSearch 域的 TLS 策略升级到 TLS 1.2,确保服务的持续可用性和安全性。 🚨 重要通知 截止日期: 2026 年 4 月 20 日 影响: 使用 TLS 1.0/1.1 的域将…

作者头像 李华
网站建设 2026/7/18 4:02:39

深度学习毕设项目:基于人工智能深度学习的土豆疾病识别

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华
网站建设 2026/7/18 13:54:18

Spring Boot Admin与Kubernetes集成监控

摘要 本文深入探讨Spring Boot Admin与Kubernetes的集成监控方案&#xff0c;包括容器化部署、服务发现、资源监控等关键技术点。通过详细的技术解析和实践示例&#xff0c;帮助开发者构建基于Kubernetes的微服务监控体系。 1. 引言 Kubernetes作为容器编排的标准&#xff0c;与…

作者头像 李华
网站建设 2026/7/19 20:00:06

强烈安利!专科生毕业论文必备TOP9 AI论文平台

强烈安利&#xff01;专科生毕业论文必备TOP9 AI论文平台 2026年专科生论文写作工具测评&#xff1a;为什么你需要这份榜单&#xff1f; 随着AI技术在学术领域的深入应用&#xff0c;越来越多的专科生开始借助智能工具提升论文写作效率。然而面对市场上琳琅满目的AI论文平台&am…

作者头像 李华
网站建设 2026/7/21 3:45:34

【毕业设计】机器学习 基于python-cnn深度学习的罗马数据集训练识别

博主介绍&#xff1a;✌️码农一枚 &#xff0c;专注于大学生项目实战开发、讲解和毕业&#x1f6a2;文撰写修改等。全栈领域优质创作者&#xff0c;博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java、小程序技术领域和毕业项目实战 ✌️技术范围&#xff1a;&am…

作者头像 李华