启动弹簧引导应用程序时的 Bean 创建错误

2022-09-01 15:08:23

当我尝试运行我的弹簧启动应用程序时,我得到这个异常:

org.springframework.beans.factory.BeanCreationException: 在类路径资源 [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class] 中创建名为“configurationPropertiesBeans”的 bean 时出错:合并 Bean 定义的后处理失败;嵌套的异常是 java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3764951d]

我认为这是一个版本不兼容。我在我的pom中导入了开放式假.xml之后它就不起作用了,但我不知道如何解决这个问题。我使用开放式假冒2.2.5.RELEASE。这是我的.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>

答案 1

为了详细说明@M-deinum的评论,将Spring Boot版本设置为(而不是在我的情况下)解决了这个问题。这意味着改变:2.3.4.RELEASE2.4.2gradle

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

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

答案 2

我遇到了同样的问题,并且由于Spring Cloud服务和Spring Boot版本问题而发生。我通过使用 https://start.spring.io/ 来生成我的项目来摆脱它。

选择项目所需的所有依赖项后,可以单击“浏览”按钮并检查文件。pom.xml

当我尝试在生成项目后向添加依赖项时,发生了此问题,因此使用IntelliJ。Eureka-clientpom.xml

我得到了同样的错误。

然后我转到 Spring.io 再次选择我用于项目的依赖项以及依赖项,单击“浏览”按钮,看到我需要在java版本下添加这行代码Eureka-clientpom.xml

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

但也有这条线:

<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>

所以我只是把它复制粘贴到我现有的,它的工作原理!pom.xml


推荐