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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47907236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:51:22  来源:igfitidea点击:

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

javaspring-bootjedisspring-data-redis

提问by user87407

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

我正在尝试在 spring-boot 应用程序中使用 spring-data-redis 来处理 redis。我正在创建JedisConnectionFactory如下:

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:

我的 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?

是不是因为 spring-boot 和 spring-data-redis 的依赖版本不兼容?我如何知道要使用哪些版本?

回答by mp911de

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

您的问题来自 Spring Boot、Spring Data Commons 和 Spring Data Redis 之间的不兼容。

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

理想情况下,您在使用 Spring Boot 的Gradle 插件时不要指定任何版本,因为 Spring Boot 为您的依赖项提供了依赖项管理,以确保跨引用库的兼容性。

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.

一般来说,Spring Boot 应该是你的依赖版本的主人。Spring Data 2.x 与 Spring Boot 1.x 不兼容。请升级到最近的 Spring Boot 里程碑(截至目前为 2.0 M7)或将 Spring Data Redis 降级到 1.7.x。

回答by Simon Park

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]

java.lang.NoSuchMethodError: org.springframework.data.repository.config.RepositoryConfigurationSource.getAttribute(Ljava/lang/String;)Ljava/util/Optional; 在 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.

我注意了第一个 jar 文件及其版本 - 2.0.2 并删除了文件 .. spring-data-jpa-2.0.2.RELEASE.jar。之后,我让父母决定它的依赖关系,并下载了 1.10.5 版本。

<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-2.0.2.RELEASE.jar(与父级冲突)

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

spring-data-jpa-1.10.5.RELEASE.jar(解决版)

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.

当遇到此错误时,每个人可能有不同的版本。但是如果您首先仔细检查它的依赖项的版本,它会更快。

回答by Abraham Imohiosen

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

您需要将 spring-boot 版本更新为 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.

这将使用 spring-core 5.0.0+,它与此版本的 spring-data-redis 兼容。