knife4j+springboot3.4异常无法正确展示文档
场景复现:
- knife4j-openapi3-jakarta-spring-boot-starter版本
<!-- https://mvnrepository.com/artifact/com.github.xiaoymin/knife4j-openapi3-jakarta-spring-boot-starter -->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.5.0</version>
</dependency>原来使用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.<init>(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版本
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-common -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-common</artifactId>
<version>2.7.0</version>
</dependency>结论:期待knife4j-openapi3-jakarta-spring-boot-starter早日升级,兼容最新版本的spring;
开源SDK:https://github.com/mingyang66/spring-parent
到此这篇关于knife4j+springboot3.4异常无法正确展示文档的文章就介绍到这了,更多相关knife4j springboot3.4异常无法展示内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
用Rational Rose逆向工程(java)生成类图(教程和错误解决)
Rational Rose有个很方便的功能,将项目中的JAVA代码自动转换成UML类图2013-02-02
java多线程之wait(),notify(),notifyAll()的详解分析
本篇文章是对java多线程 wait(),notify(),notifyAll()进行了详细的分析介绍,需要的朋友参考下2013-06-06
SpringCloud+RocketMQ实现分布式事务的实践
分布式事务已经成为了我们的经常使用的。所以我们来一步一步的实现基于RocketMQ的分布式事务。感兴趣的可以了解一下2021-10-10


最新评论