NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute

user87407 picture user87407 · Dec 20, 2017 · Viewed 22.2k times · Source

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?

Answer

mp911de picture mp911de · Dec 20, 2017

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.