Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bean creation error when starting spring boot application

When i try to run my spring boot application i get this Exception:

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; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans] from 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. I use open feign 2.2.5.RELEASE. Here my 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>
like image 363
NyeSass Avatar asked Dec 07 '20 12:12

NyeSass


People also ask

What is Bean Creation exception in Spring boot?

NoSuchBeanDefinitionException. By far, the most common cause of the BeanCreationException is Spring trying to inject a bean that doesn't exist in the context. For example, BeanA is trying to inject BeanB: @Component public class BeanA { @Autowired private BeanB dependency; ... }

Can not create bean Spring?

There could be numerous reasons why Spring could not able to create a bean with name X, but clue always lies on the detailed stack trace. This error always has some underlying cause e.g. a ClassNotFoundException or a NoClassDefFoundError, which potentially signal a missing JAR file in the classpath.

How do you fix bean instantiation through factory method failure?

Solution 1 The bean object could not have been created for an abstract class. It is necessary to create a new class that extends the abstract class. If the bean factory is attempting to get the bean by using the abstract class name, it can find and associate the implemented class. The exception would then be resolved.


4 Answers

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. In gradle this meant changing:

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

To

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'
    ...
}
like image 83
asherbret Avatar answered Oct 17 '22 01:10

asherbret


I had a same issue, and it is happening because of Spring Cloud services and Spring Boot version issues. I got rid of it by using https://start.spring.io/ to generate my project.

When you select all dependencies needed for your project, you can then click the Explore button and check the pom.xml file.

This issue happened to me when I tried to add dependency for Eureka-client to my pom.xml after generating project, so using 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

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

like image 21
user9347049 Avatar answered Oct 17 '22 01:10

user9347049


You need to change spring boot version to Released version

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>
like image 14
nitish kumar Avatar answered Oct 17 '22 01:10

nitish kumar


Spring-Cloud - Hoxton.SR8 is not compatiable with 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>
like image 8
kou logn Avatar answered Oct 17 '22 00:10

kou logn