本文介紹了啟動Spring Boot應用程序時出現Bean創建錯誤的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
當我嘗試運行我的Spring Boot應用程序時,我收到以下異常:
org.springframework.beans.factory.BeanCreationException:錯誤
創建在中定義的名為”ConfigurationPropertiesBeans”的Bean
類路徑資源
[org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]:
合并Bean定義的后處理失敗;嵌套異常為
Java.lang.IlLegalStateException:未能自省類
[org.springframework.cloud.context.properties.ConfigurationPropertiesBeans]
從ClassLoader
[jdk.internal.loader.ClassLoaders$AppClassLoader@3764951d]
我認為這是版本不兼容。我在我的pom.xml中導入了Open Feign,之后它就不起作用了,但我不知道如何修復它。我用的是OPEN FIGN 2.2.5版本。
這里是我的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 Boot版本設置為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 Boot應用程序時出現Bean創建錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,