创建名为“configDataContextRefresh”的Bean时出错[SpringBoot]

jdzmm42g  于 2022-12-10  发布在  Spring
关注(0)|答案(5)|浏览(308)

I'm working on a Spring Boot project. I got a weird error when I executed the command mvn clean install .
Below is the error:

java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configDataContextRefresher' defined in class path resource [org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.context.refresh.ConfigDataContextRefresher]: Factory method 'configDataContextRefresher' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/ConfigurableBootstrapContext
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.context.refresh.ConfigDataContextRefresher]: Factory method 'configDataContextRefresher' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/ConfigurableBootstrapContext
Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/ConfigurableBootstrapContext
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.ConfigurableBootstrapContext

I really do not understand what is "configDataContextRefresher" . I confirm that I don't use any configDataContextRefresher in my code. Besides, the whole error from the doesn't tell me where any locations where the error occurs on my code.
I've been trying to solve it for 2-3 hours and also fount nothing on the internet.
Please help. Thanks a lot !
---Edit--- More clues, I can do a mvn spring-boot:run to run the service. But I can't build the jar file.

gudnpqoy

gudnpqoy1#

我遇到了同样问题,通过在pom.xml中添加内部属性标记,这个问题得到了解决:

<properties>
    <java.version>1.8</java.version> 
    <springcloud.version>Hoxton.SR1</spring-cloud.version>
</properties>

并注解掉即将到来的默认属性标记。

mpgws1up

mpgws1up2#

在我的例子中,一个太旧的spring-boot版本有一个问题。在将版本改为2.6.2后,这个问题就消失了。

x759pob2

x759pob23#

这可能是由于当您添加一些依赖项(如Eureka )时,Sping Boot 版本和properties标记之间(在您的Pom.xml文件中)不一致。
您始终可以通过检查Explore〉Pom.xml部分来确保您是否使用了Spring Initializr中的当前设置

<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.7.3</version>
 <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
 <java.version>17</java.version>
 <spring-cloud.version>2021.0.3</spring-cloud.version>
</properties>
dba5bblo

dba5bblo4#

帮助我的是从以下位置更新spring-boot-starter-parent artifactId版本:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.2.RELEASE</version>
    <relativePath/> 
</parent>

至:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.6.6</version>
    <relativePath/>
</parent>

然后,Eureka 客户端顺利注册。

lxkprmvk

lxkprmvk5#

我找到了一个解决方法,即使用

  • 跳过测试
    但我认为应该有更好的解决方案来消除这个奇怪的错误。

相关问题