当前位置: 代码网 > it编程>编程语言>Java > knife4j+springboot3.4异常无法正确展示文档

knife4j+springboot3.4异常无法正确展示文档

2025年01月14日 Java 我要评论
场景复现:knife4j-openapi3-jakarta-spring-boot-starter版本<!-- https://mvnrepository.com/artifact/com.gi

场景复现:

  • 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异常无法展示内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com