springboot3导入knife4j-openapi3-jakarta-spring-boot-starter并且使用@RestContrller出现不能访问接口文档问题
遇到这种问题就去查看maven依赖树排除旧依赖导入新依赖。
·
问题

解决思路
查看异常信息显示
发现是因为 没有这个但对象的构造函数 大概率是因为版本依赖问题了
去查看一下这个版本的本函数的构造方法
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;
}
发现这个函数是多个参数 但是我们需要的是单个参数的
//这个类是package org.springframework.web.method; 也就是springweb依赖的内容
ControllerAdviceBean
//导致依赖问题的第二个地方 org.springdoc.core.service 这个包
//也就是springdoc-openapi-starter-webmvc-ui依赖
GenericResponseService.java:702
现在就可以有两个解决思路了
降低springweb依赖的版本
降低springweb依赖的版本 提供单参数的构造方法 也就是降低springboot的版本 我这个项目依赖比较复杂 不方便降低版本所以我就采用第二种 所以我就不写这个代码了 提供第二个代码
升高webui依赖版本
第二个方法就是升级webui这个依赖版本 让他调用多参数构造方法
代码
<!-- 排除旧版本的依赖-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
<exclusions>
<exclusion>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 引入新版本依赖-->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.3</version>
</dependency>
总结
遇到这种问题就去查看maven依赖树 排除旧依赖 导入新依赖
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)