Error With ConfigurationPropertiesBinder java spring when trying to start application context

Issue

I have a simple application it fails to load with the below error


APPLICATION FAILED TO START


Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.springframework.boot.context.properties.ConfigurationPropertiesBinder.register(ConfigurationPropertiesBinder.java:202)

The following method did not exist:

'org.springframework.beans.factory.support.BeanDefinitionBuilder org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition(java.lang.Class, java.util.function.Supplier)'

The calling method’s class, org.springframework.boot.context.properties.ConfigurationPropertiesBinder, was loaded from the following location:

jar:file:/C:/Users/Kedem/.m2/repository/org/springframework/boot/spring-boot/2.6.6/spring-boot-2.6.6.jar!/org/springframework/boot/context/properties/ConfigurationPropertiesBinder.class

The called method’s class, org.springframework.beans.factory.support.BeanDefinitionBuilder, is available from the following locations:

jar:file:/C:/Users/Kedem/.m2/repository/org/springframework/spring-beans/5.3.1/spring-beans-5.3.1.jar!/org/springframework/beans/factory/support/BeanDefinitionBuilder.class

The called method’s class hierarchy was loaded from the following locations:

org.springframework.beans.factory.support.BeanDefinitionBuilder: file:/C:/Users/Kedem/.m2/repository/org/springframework/spring-beans/5.3.1/spring-beans-5.3.1.jar

Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.context.properties.ConfigurationPropertiesBinder and org.springframework.beans.factory.support.BeanDefinitionBuilder

this is my pom file:

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>test1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.6</version>
        <relativePath/>
    </parent>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.telegram</groupId>
            <artifactId>telegrambots</artifactId>
            <version>6.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>5.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-autoconfigure</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.6.6</version>
        </dependency>


    </dependencies>
</project>

this is my main class

package com.test1.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = "com.test1")
public class MainClass {

    public static void main(String[] args) {
        SpringApplication.run(MainClass.class, args);
    }
}

this is my application.properties

bot.username=12345
bot.token=abcdsadsadsasa

Some service class

package com.test1.api;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;

    @Service
    public class Test1Api {
    
    
        @Autowired
        public Test1Api(@Value("${bot.username:12345}") String botUserName, @Value("${bot.token:dsadsadsadsa") String botToken) {
            try {
                TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
                telegramBotsApi.registerBot(new Nadlan1Bot(botUserName, botToken));
            } catch (TelegramApiException e) {
                e.printStackTrace();
            }
        }
    }

Solution

Remove the spring-beans dependency.

Answered By – James S

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published