knife4j+springboot3.4異常無(wú)法正確展示文檔
場(chǎng)景復(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>原來(lái)使用springboot3.3.5版本,先升級(jí)到3.4.0版本
通過(guò)http://ip:port/doc.html訪問(wèn)接口文檔發(fā)現(xiàn)訪問(wèn)/v3/api-docs接口時(shí)報(bào)
Handler dispatch failed: java.lang.NoSuchMethodError: 'void org.springframework.web.method.ControllerAdviceBean.<init>(java.lang.Object)
通過(guò)分析異常日志發(fā)現(xiàn)是ControllerAdviceBean類報(bào)錯(cuò),在springboot3.3.5時(shí)spring-web版本是6.1.14,springboot3.4版本是6.2.0版本。
通過(guò)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類使用一個(gè)參數(shù)的構(gòu)造函數(shù),但是報(bào)異常):
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個(gè),已經(jīng)不存在一個(gè)參數(shù)的構(gòu)造函數(shù)了。
- springdoc-openapi-starter-common文檔當(dāng)前已經(jīng)升級(jí)到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早日升級(jí),兼容最新版本的spring;
開(kāi)源SDK:https://github.com/mingyang66/spring-parent
到此這篇關(guān)于knife4j+springboot3.4異常無(wú)法正確展示文檔的文章就介紹到這了,更多相關(guān)knife4j springboot3.4異常無(wú)法展示內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
如何讓W(xué)in10實(shí)現(xiàn)Java文件的開(kāi)機(jī)自啟動(dòng)
這篇文章主要介紹了如何讓W(xué)in10實(shí)現(xiàn)Java文件的開(kāi)機(jī)自啟動(dòng),對(duì)于一些想要一直運(yùn)行的Java文件,就會(huì)造成每次系統(tǒng)更新之后的重啟導(dǎo)致Java文件無(wú)法繼續(xù)運(yùn)行。,需要的朋友可以參考下2019-06-06
spring boot配置ssl實(shí)現(xiàn)HTTPS的方法
這篇文章主要介紹了spring boot配置ssl實(shí)現(xiàn)HTTPS的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-03-03
Springboot3整合Mybatis-plus3.5.3報(bào)錯(cuò)問(wèn)題解決
在日常學(xué)習(xí)springboot3相關(guān)的代碼時(shí),在使用 SpringBoot3 整合 MyBatisplus 時(shí)出現(xiàn)了一些問(wèn)題,花了不少時(shí)間處理,這篇文章主要介紹了Springboot3整合Mybatis-plus3.5.3報(bào)錯(cuò)問(wèn)題解決,需要的朋友可以參考下2023-11-11
java web學(xué)習(xí)_淺談request對(duì)象中g(shù)et和post的差異
下面小編就為大家?guī)?lái)一篇java web學(xué)習(xí)_淺談request對(duì)象中g(shù)et和post的差異。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05
idea中service或者mapper引入報(bào)紅的問(wèn)題及解決
在使用IntelliJ IDEA開(kāi)發(fā)SpringBoot項(xiàng)目時(shí),有時(shí)會(huì)遇到Service或Mapper接口引入時(shí)報(bào)紅但不影響項(xiàng)目運(yùn)行的情況,這主要是因?yàn)镮DEA的檢查級(jí)別設(shè)置問(wèn)題,解決方法是將有問(wèn)題的Error級(jí)別改為編譯通過(guò)的安全級(jí)別,即可消除報(bào)紅2024-09-09
java實(shí)現(xiàn)RedisTemplate操作哈希數(shù)據(jù)
RedisTemplate是Spring Data Redis提供的一個(gè)用于操作Redis的模板類,本文主要介紹了java實(shí)現(xiàn)RedisTemplate操作哈希數(shù)據(jù),具有一定的參考價(jià)值,感興趣的可以了解一下2024-09-09
java調(diào)用process線程阻塞問(wèn)題的解決
這篇文章主要介紹了java調(diào)用process線程阻塞問(wèn)題的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06

