构建应用程序时出现 Spring Boot 错误

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

我在构建 Spring Boot 时收到以下错误,它指出创建 bean 时出错。您能指导我解决该错误吗?

024-12-07T01:14:52.917+05:30  INFO 1142 --- [DemoApp2] [           main] c.example.DemoApp2.DemoApp2Application   : Starting DemoApp2Application using Java 23.0.1 with PID 1142 (/Users/vishaalarun/Downloads/DemoApp2/target/classes started by vishaalarun in /Users/vishaalarun/Downloads/DemoApp2)
2024-12-07T01:14:52.918+05:30  INFO 1142 --- [DemoApp2] [           main] c.example.DemoApp2.DemoApp2Application   : No active profile set, falling back to 1 default profile: "default"
2024-12-07T01:14:53.193+05:30  WARN 1142 --- [DemoApp2] [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientHttpRequestFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/http/client/HttpClientAutoConfiguration.class]: Post-processing of merged bean definition failed
2024-12-07T01:14:53.196+05:30  INFO 1142 --- [DemoApp2] [           main] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-12-07T01:14:53.204+05:30 ERROR 1142 --- [DemoApp2] [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientHttpRequestFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/http/client/HttpClientAutoConfiguration.class]: Post-processing of merged bean definition failed
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:578) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:288) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1122) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1093) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1030) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:987) ~[spring-context-6.2.0.jar:6.2.0]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.2.0.jar:6.2.0]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.4.0.jar:3.4.0]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.4.0.jar:3.4.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.4.0.jar:3.4.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.4.0.jar:3.4.0]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.4.0.jar:3.4.0]
    at com.example.DemoApp2.DemoApp2Application.main(DemoApp2Application.java:10) ~[classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.http.client.JdkClientHttpRequestFactoryBuilder] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@5a07e868]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483) ~[spring-core-6.2.0.jar:6.2.0]
    at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:320) ~[spring-core-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.buildLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:297) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:274) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.findLifecycleMetadata(InitDestroyAnnotationBeanPostProcessor.java:203) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(InitDestroyAnnotationBeanPostProcessor.java:182) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:312) ~[spring-context-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:1099) ~[spring-beans-6.2.0.jar:6.2.0]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575) ~[spring-beans-6.2.0.jar:6.2.0]
    ... 16 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/springframework/http/client/JdkClientHttpRequestFactory
    at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
    at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3650) ~[na:na]
    at java.base/java.lang.Class.getDeclaredMethods(Class.java:2735) ~[na:na]
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465) ~[spring-core-6.2.0.jar:6.2.0]
    ... 24 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.springframework.http.client.JdkClientHttpRequestFactory
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[na:na]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[na:na]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:528) ~[na:na]
    ... 28 common frames omitted


Process finished with exit code 1

我尝试升级和降级我的 Java 版本,但它抛出了相同的错误

java spring spring-boot maven
1个回答
0
投票

它在错误消息中告诉您问题是什么。您的 maven 或 gradle 配置中没有适当的库。或者,您需要重新编译,以便从您的配置生成适当的类。

Caused by: java.lang.ClassNotFoundException: org.springframework.http.client.JdkClientHttpRequestFactory

通过快速搜索该包,您需要根据您需要的版本确保您具有以下依赖项

Maven

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>6.2.0</version>
</dependency>

摇篮

implementation group: 'org.springframework', name: 'spring-web', version: '6.2.0'
© www.soinside.com 2019 - 2024. All rights reserved.