簡體   English   中英

啟動 spring 啟動應用程序時 bean 創建錯誤

[英]bean creation error when starting spring boot application

當我嘗試運行我的 spring 引導應用程序時,出現此異常:

org.springframework.beans.factory.BeanCreationException:在 class 路徑資源 [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class] 中創建名為“configurationPropertiesBeans”的 bean 時出錯:合並 bean 定義的后處理失敗; 嵌套異常是 java.lang.IllegalStateException:無法自省 Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] 來自 ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@3764951d]

我認為這是版本不兼容。 我在我的 pom.xml 中導入了 open feign,之后它就不起作用了,但我不知道如何解決這個問題。 我使用 open feign 2.2.5.RELEASE。 這是我的 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>

為了詳細說明@M-deinum 的評論,將 Spring 引導版本設置為2.3.4.RELEASE (在我的情況下不是2.4.2 )解決了這個問題。 gradle ,這意味着改變:

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

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

我遇到了同樣的問題,這是因為 Spring 雲服務和 Spring 啟動版本問題。 我通過使用https://start.spring.io/來生成我的項目來擺脫它。

當您 select 項目所需的所有依賴項時,您可以單擊瀏覽按鈕並檢查pom.xml文件。

當我在生成項目后嘗試將Eureka-client的依賴項添加到我的pom.xml時,這個問題發生在我身上,因此使用 IntelliJ。

我得到了同樣的錯誤。

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>

但也有這行:

<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並且它有效!

您需要將 spring 引導版本更改為已發布版本

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

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

所以這似乎是 SpringBoot vs Cloud Services 版本兼容性問題。 有沒有一點可以看到Spring框架傘整體的版本兼容性矩陣? 謝謝!

Spring-Cloud - Hoxton.SR8 與 Spring-boot 2.4.0 不兼容

只需使用任何一種組合:

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

或者

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

您需要遵循 Spring Cloud 的發布序列並匹配 Spring-boot 啟動器的版本。 發布火車可在 spring-cloud 網站https://spring.io/projects/spring-cloud

目前發布的火車是: spring-cloud的發布火車

只是更改為:

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

並將版本添加到

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

為我工作得很好

這對我有用。 Go ti spring 初始化啟動。spring.ZF98ED07A4D5F50F7DE1Z410 再次添加。 將 your.pom 與下載的 pom 進行比較。 我得到了我的問題。

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

我有不同版本的 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>

將此添加到存儲庫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM