升级到 Spring Boot 3.x 和 Spring 6.x 后,如何修复 Java Spring 中 handlerExceptionResolver 的 BeanCreationException?

问题描述 投票:0回答:1

我的应用程序同时使用 Spring Boot 和 Spring 依赖项。由于

spring-web
存在安全漏洞,我们必须从
5.3.33
更新到
6.x
。目前我们使用的是 Spring Boot 版本
2.7.18
,它使用 Spring 框架
5.x

将项目从

Java 11
更新到
Java 17
以及 Spring boot starter 父级和更具体的 Spring Boot 版本从
2.7.18
3.2.0
中的
pom.xml
后,我终于从
spring-web 更新了 
5.3.33
 
6.0.19
,并修复了构建过程中指出的版本之间的一些代码不兼容问题。

尝试使用命令

mvn spring-boot:run
运行应用程序时,应用程序构建成功,但无法启动。我收到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handlerExceptionResolver' defined in class path resource [org/springframework/boot/autoconfigure /web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Failed to instantiate [org.springframework.web.servlet.HandlerExceptionResolver]: Factory method 'handlerExceptionResolver' threw exception with message: org/springframework/web/util/DisconnectedClientHelper

谷歌搜索,查看类似的问题并使用人工智能建议修复项目内的

handlerExceptionResolver
实现,但我没有该类的任何实现。

大家有遇到过这个问题吗?如果是的话,你是怎么解决的?

干杯!

编辑:

pom.xml
文件可以在这里找到:https://pastebin.com/rPDdckDQ

完整的堆栈跟踪:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'handlerExceptionResolver' defined in class path resource [org/springframework/boot/autoconfigure
/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Failed to instantiate [org.springframework.web.servlet.HandlerExceptionResolver]: Factory method 'handlerExceptionResolver' threw exception with message: org/springframework/web/util/DisconnectedClientHelper
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:655) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:643) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1166) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563) ~[spring-beans-6.1.1.jar:6.1.1]       
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:946) ~[spring-context-6.1.1.jar:6.1.1]        
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:616) ~[spring-context-6.1.1.jar:6.1.1]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.0.jar:3.2.0]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:753) [spring-boot-3.2.0.jar:3.2.0]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:455) [spring-boot-3.2.0.jar:3.2.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:323) [spring-boot-3.2.0.jar:3.2.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1342) [spring-boot-3.2.0.jar:3.2.0]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1331) [spring-boot-3.2.0.jar:3.2.0]
        at com.verint.useragentservice.UseragentServiceApplication.main(UseragentServiceApplication.java:16) [classes/:?]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) [spring-boot-devtools-3.2.0.jar:3.2.0]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerExceptionResolver]: Factory method 'handlerExceptionResolver' threw exception with message: org/springframework/web/util/DisconnectedClientHelper
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:178) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-6.1.1.jar:6.1.1]
        ... 24 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/util/DisconnectedClientHelper
        at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.<clinit>(ExceptionHandlerExceptionResolver.java:87) ~[spring-webmvc-6.1.1.jar:6.1.1] 
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.createExceptionHandlerExceptionResolver(WebMvcConfigurationSupport.java:1079) ~[spring-webmvc-6.1.1.jar:6.1.1]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration.createExceptionHandlerExceptionResolver(WebMvcAutoConfiguration.java:554) ~[spring-boot-autoconfigure-3.2.0.jar:3.2.0]
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.addDefaultHandlerExceptionResolvers(WebMvcConfigurationSupport.java:1051) ~[spring-webmvc-6.1.1.jar:6.1.1]
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.handlerExceptionResolver(WebMvcConfigurationSupport.java:1005) ~[spring-webmvc-6.1.1.jar:6.1.1] 
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-6.1.1.jar:6.1.1]
        ... 24 more
Caused by: java.lang.ClassNotFoundException: org.springframework.web.util.DisconnectedClientHelper
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?]
        at org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver.<clinit>(ExceptionHandlerExceptionResolver.java:87) ~[spring-webmvc-6.1.1.jar:6.1.1] 
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.createExceptionHandlerExceptionResolver(WebMvcConfigurationSupport.java:1079) ~[spring-webmvc-6.1.1.jar:6.1.1]
        at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration.createExceptionHandlerExceptionResolver(WebMvcAutoConfiguration.java:554) ~[spring-boot-autoconfigure-3.2.0.jar:3.2.0]
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.addDefaultHandlerExceptionResolvers(WebMvcConfigurationSupport.java:1051) ~[spring-webmvc-6.1.1.jar:6.1.1]
        at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.handlerExceptionResolver(WebMvcConfigurationSupport.java:1005) ~[spring-webmvc-6.1.1.jar:6.1.1] 
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:140) ~[spring-beans-6.1.1.jar:6.1.1]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-6.1.1.jar:6.1.1]
        ... 24 more
spring-boot maven dependencies
1个回答
0
投票

我的问题在评论中得到了回答,但我想我应该发布一个单独的答案来强调它: “事实上,你有一个 classnotfound 通常是由于依赖管理过于聪明。正如你已经看到的,你正在将版本与 spring-web 依赖项混合在一起(你使用 6.0.19,而 Spring Boot 的其余部分需要 6.1.1)。 ”.

因此,我清理了

pom.xml
中多余的依赖项和版本,并将
spring-web
依赖项更改为
6.1.1

© www.soinside.com 2019 - 2024. All rights reserved.