knife4j+springboot3.4異常無法正確展示文檔
場景復(fù)現(xiàn):
- 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訪問接口文檔發(fā)現(xiàn)訪問/v3/api-docs接口時報
Handler dispatch failed: java.lang.NoSuchMethodError: 'void org.springframework.web.method.ControllerAdviceBean.<init>(java.lang.Object)
通過分析異常日志發(fā)現(xiàn)是ControllerAdviceBean類報錯,在springboot3.3.5時spring-web版本是6.1.14,springboot3.4版本是6.2.0版本。
通過springboot全局異常捕獲堆棧信息發(fā)現(xiàn):
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類使用一個參數(shù)的構(gòu)造函數(shù),但是報異常):
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的構(gòu)造函數(shù):
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的構(gòu)造函數(shù):
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; }
此類中的構(gòu)造函數(shù)已經(jīng)變更為4個,已經(jīng)不存在一個參數(shù)的構(gòu)造函數(shù)了。
- springdoc-openapi-starter-common文檔當前已經(jīng)升級到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>
結(jié)論:期待knife4j-openapi3-jakarta-spring-boot-starter早日升級,兼容最新版本的spring;
開源SDK:https://github.com/mingyang66/spring-parent
到此這篇關(guān)于knife4j+springboot3.4異常無法正確展示文檔的文章就介紹到這了,更多相關(guān)knife4j springboot3.4異常無法展示內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
用Rational Rose逆向工程(java)生成類圖(教程和錯誤解決)
Rational Rose有個很方便的功能,將項目中的JAVA代碼自動轉(zhuǎn)換成UML類圖2013-02-02java多線程之wait(),notify(),notifyAll()的詳解分析
本篇文章是對java多線程 wait(),notify(),notifyAll()進行了詳細的分析介紹,需要的朋友參考下2013-06-06SpringCloud+RocketMQ實現(xiàn)分布式事務(wù)的實踐
分布式事務(wù)已經(jīng)成為了我們的經(jīng)常使用的。所以我們來一步一步的實現(xiàn)基于RocketMQ的分布式事務(wù)。感興趣的可以了解一下2021-10-10