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异常无法展示内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Springboot3整合Mybatis-plus3.5.3报错问题解决
在日常学习springboot3相关的代码时,在使用 SpringBoot3 整合 MyBatisplus 时出现了一些问题,花了不少时间处理,这篇文章主要介绍了Springboot3整合Mybatis-plus3.5.3报错问题解决,需要的朋友可以参考下2023-11-11
java web学习_浅谈request对象中get和post的差异
下面小编就为大家带来一篇java web学习_浅谈request对象中get和post的差异。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-05-05
idea中service或者mapper引入报红的问题及解决
在使用IntelliJ IDEA开发SpringBoot项目时,有时会遇到Service或Mapper接口引入时报红但不影响项目运行的情况,这主要是因为IDEA的检查级别设置问题,解决方法是将有问题的Error级别改为编译通过的安全级别,即可消除报红2024-09-09


最新评论