NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute
Asked Answered
K

4

13

I am trying to use spring-data-redis in a spring-boot application to work with redis. I am creating JedisConnectionFactory as follows:

RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
configuration.setHostName("localhost");
configuration.setPort(6379);
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(configuration);

It throws the exception:

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional;
    at org.springframework.data.redis.repository.configuration.RedisRepositoryConfigurationExtension.registerBeansForRoot(RedisRepositoryConfigurationExtension.java:88)
    at org.springframework.data.repository.config.RepositoryConfigurationDelegate.registerRepositoriesIn(RepositoryConfigurationDelegate.java:118)
    at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:59)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsFromRegistrars(ConfigurationClassBeanDefinitionReader.java:352)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:143)
    at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:116)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:336)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:246)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
    at com.test.redis.RedisTesterApplication.main(RedisTesterApplication.java:11)

My build.gradle:

dependencies {
    compile('org.springframework.data:spring-data-redis:2.0.2.RELEASE')
    compile('redis.clients:jedis:2.9.0')
    compile('org.json:json:20160810')
    compile('org.springframework.boot:spring-boot-starter:1.4.2.RELEASE')
    compile("org.springframework:spring-web")
    compile('org.slf4j:slf4j-api:+')
}

Is it because of incompatible dependency versions for spring-boot and spring-data-redis? How can I know which versions to use?

Kings answered 20/12, 2017 at 13:32 Comment(1)
Remove the version for spring-boot-starter. Replace the spring-web dependency with spring-boot-starter-web and replace the spring-data-redis dependency with the spring-boot-starter-data-redis dependency. That way you have compatible versions. You also don't need the org.slf4j dependency the spring boot starters take care of that.Maisel
C
20

Your issue comes from incompatibilities between Spring Boot, Spring Data Commons, and Spring Data Redis.

Ideally, you don't specify any versions when using Spring Boot's Gradle plugin as Spring Boot comes with dependency management for your dependencies ensuring compatibility across the references libraries.

In general, Spring Boot should be your master for dependency versions. Spring Data 2.x is not compatible with Spring Boot 1.x. Please upgrade either to a recent Spring Boot milestone (2.0 M7 as of now) or downgrade Spring Data Redis to 1.7.x.

Clientage answered 20/12, 2017 at 13:41 Comment(1)
I could not upgrade spring-boot due to deployment environment requirements (Spring Boot 2.0 needs gradle 4.+ and we are working with 3.2.x). Nor could I downgrade spring-data-redis since I lost some of the required capabilities. So I ended up writing my own client on top of lettuce. Thanks for the help.Kings
S
7

Even though many people benefit from this framework, sometimes it takes more time troubleshooting its dependencies. It's a known issue and I had the same problem as below.

java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; at org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension.postProcess(JpaRepositoryConfigExtension.java:125) ~[spring-data-jpa-2.0.2.RELEASE.jar:2.0.2.RELEASE]

I paid attention to the 1st jar file and its version - 2.0.2 and removed of the file .. spring-data-jpa-2.0.2.RELEASE.jar. After that I let parent decide it's dependencies and it downloaded 1.10.5 version.

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
 ....
</dependencies>

spring-data-jpa-2.0.2.RELEASE.jar (conflict with parent)

spring-data-jpa-1.10.5.RELEASE.jar (resolved version)

Everyone might have different versions when they run into this error. But it would be faster if you double check with it's dependencies' version first.

Stunning answered 17/1, 2018 at 4:17 Comment(0)
T
1

You need to update your spring-boot version to 2.0.0+.

dependencies {
    compile('org.springframework.data:spring-data-redis:2.0.2.RELEASE')
    compile('redis.clients:jedis:2.9.0')
    compile('org.json:json:20160810')
    compile('org.springframework.boot:spring-boot-starter:2.0.0.RELEASE')
    compile("org.springframework:spring-web")
    compile('org.slf4j:slf4j-api:+')
}

This will use spring-core 5.0.0+, which is compatible with this version of spring-data-redis.

Tympanum answered 23/3, 2018 at 16:58 Comment(0)
D
0

An attempt was made to call the method org.springframework.data.repository.config.RepositoryConfigurationSource.getRequiredAttribute(Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object; but it does not exist. Its class, org.springframework.data.repository.config.RepositoryConfigurationSource, is available from the following locations:

jar:file:/C:/Users/1002899/.m2/repository/org/springframework/data/spring-data-commons/2.1.3.RELEASE/spring-data-commons-2.1.3.RELEASE.jar!/org/springframework/data/repository/config/RepositoryConfigurationSource.class

It was loaded from the following location:

file:/C:/Users/1002899/.m2/repository/org/springframework/data/spring-data-commons/2.1.3.RELEASE/spring-data-commons-2.1.3.RELEASE.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.data.repository.config.RepositoryConfigurationSource

Devalue answered 16/10, 2021 at 5:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.