knife4j+springboot3.4異常無法正確展示文檔
場景復現(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類使用一個參數的構造函數,但是報異常):
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異常無法展示內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- Springboot3集成Knife4j的步驟以及使用(最完整版)
- SpringBoot?Knife4j框架&Knife4j的顯示內容的配置方式
- SpringBoot與knife4j的整合使用過程
- springboot讀取bootstrap配置及knife4j版本兼容性問題及解決
- springboot3整合knife4j詳細圖文教程(swagger增強)
- springboot整合knife4j全過程
- knife4j?整合?springboot的過程詳解
- SpringBoot中使用Knife4J的解決方案
- springboot集成swagger3與knife4j的詳細代碼
- Springboot中整合knife4j接口文檔的過程詳解
相關文章
Mybatis在sqlite中無法讀寫byte[]類問題的解決辦法
這篇文章主要給大家介紹了關于Mybatis在sqlite中無法讀寫byte[]類問題的解決辦法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-10-10springmvc學習筆記-返回json的日期格式問題的解決方法
本篇文章主要介紹了springmvc學習筆記-返回json的日期格式問題的解決方法,解決了日期格式的輸出,有興趣的可以了解一下。2017-01-01如何使用BigDecimal實現(xiàn)Java開發(fā)商業(yè)計算
這篇文章主要介紹了如何使用BigDecimal實現(xiàn)Java開發(fā)商業(yè)計算,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-09-09