简体   繁体   English

启动 spring 启动应用程序时 bean 创建错误

[英]bean creation error when starting spring boot application

When i try to run my spring boot application i get this Exception:当我尝试运行我的 spring 引导应用程序时,出现此异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationPropertiesBeans' defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Post-processing of merged bean definition failed; org.springframework.beans.factory.BeanCreationException:在 class 路径资源 [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class] 中创建名为“configurationPropertiesBeans”的 bean 时出错:合并 bean 定义的后处理失败; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3764951d]嵌套异常是 java.lang.IllegalStateException:无法自省 Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] 来自 ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3764951d]

I think it's an version incompatibility.我认为这是版本不兼容。 I imported open feign in my pom.xml and after that it wasn't working, but i dont know how to fix that.我在我的 pom.xml 中导入了 open feign,之后它就不起作用了,但我不知道如何解决这个问题。 I use open feign 2.2.5.RELEASE.我使用 open feign 2.2.5.RELEASE。 Here my pom.xml:这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>privas.microservice</groupId>
    <artifactId>sellcar</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sellcar</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>15</java.version>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>2.0.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>2.4.1</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

To elaborate on @M-deinum's comment, setting Spring Boot version to 2.3.4.RELEASE (instead of 2.4.2 in my case) solved the issue.为了详细说明@M-deinum 的评论,将 Spring 引导版本设置为2.3.4.RELEASE (在我的情况下不是2.4.2 )解决了这个问题。 In gradle this meant changing:gradle ,这意味着改变:

plugins {
    id 'org.springframework.boot' version '2.4.2'
    ...
}

To

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    ...
}

I had a same issue, and it is happening because of Spring Cloud services and Spring Boot version issues.我遇到了同样的问题,这是因为 Spring 云服务和 Spring 启动版本问题。 I got rid of it by using https://start.spring.io/ to generate my project.我通过使用https://start.spring.io/来生成我的项目来摆脱它。

When you select all dependencies needed for your project, you can then click the Explore button and check the pom.xml file.当您 select 项目所需的所有依赖项时,您可以单击浏览按钮并检查pom.xml文件。

This issue happened to me when I tried to add dependency for Eureka-client to my pom.xml after generating project, so using IntelliJ.当我在生成项目后尝试将Eureka-client的依赖项添加到我的pom.xml时,这个问题发生在我身上,因此使用 IntelliJ。

I got the same error.我得到了同样的错误。

Then I went to Spring.io again select dependencies that I use for my project and also dependency for Eureka-client , clicked on Explore button and saw that I need to add this line of code under java version in pom.xml Then I went to Spring.io again select dependencies that I use for my project and also dependency for Eureka-client , clicked on Explore button and saw that I need to add this line of code under java version in pom.xml

<spring-cloud.version>2020.0.3</spring-cloud.version>

But also this lines as well:但也有这行:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

So I just copy pasted it to my existing pom.xml and it worked!所以我只是将它复制粘贴到我现有的pom.xml并且它有效!

You need to change spring boot version to Released version您需要将 spring 引导版本更改为已发布版本

from

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

to

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

So this is SpringBoot vs Cloud Services version compatibility issue it seems.所以这似乎是 SpringBoot vs Cloud Services 版本兼容性问题。 Is there any one point where we can see the version compatibility matrix for Spring framework umbrella as a whole?有没有一点可以看到Spring框架伞整体的版本兼容性矩阵? Thanks!谢谢!

Spring-Cloud - Hoxton.SR8 is not compatiable with Spring-boot 2.4.0 Spring-Cloud - Hoxton.SR8 与 Spring-boot 2.4.0 不兼容

Just use either of the combinations:只需使用任何一种组合:

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

<spring-cloud.version>2020.0.3</spring-cloud.version>

Or或者

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

<spring-cloud.version>Hoxton.SR8</spring-cloud.version>

You need to follow the release train of Spring Cloud and match the version of the Spring-boot starter.您需要遵循 Spring Cloud 的发布序列并匹配 Spring-boot 启动器的版本。 The release train is available on the spring-cloud website https://spring.io/projects/spring-cloud发布火车可在 spring-cloud 网站https://spring.io/projects/spring-cloud

The release train as of now is: Release train for spring-cloud目前发布的火车是: spring-cloud的发布火车

just Changing to:只是更改为:

 <dependency>                                                                          
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>3.1.1</version>
</dependency>

and Adding version to并将版本添加到

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.6.6</version>
        </plugin>
    </plugins>
</build>

Worked Fine For Me为我工作得很好

This worked for me.这对我有用。 Go ti spring initialize start.spring.io and add the dependancies again. Go ti spring 初始化启动。spring.ZF98ED07A4D5F50F7DE1Z410 再次添加。 Compare your.pom with downloaded pom.将 your.pom 与下载的 pom 进行比较。 I got my issue.我得到了我的问题。

<spring-cloud.version>2021.0.3-SNAPSHOT</spring-cloud.version> <spring-cloud.version>2021.0.3-SNAPSHOT</spring-cloud.version>

I was having diffent version of spring cloud hence there was a conflict.我有不同版本的 spring 云,因此发生了冲突。

 <repository>
      <id>netflix-candidates</id>
      <name>Netflix Candidates</name>
      <url>https://artifactory-oss.prod.netflix.net/artifactory/maven-oss-candidates</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>

add this to the repository将此添加到存储库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM