spring-data-redis版本冲突引发的问题

Posted zhengwangzw

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring-data-redis版本冲突引发的问题相关的知识,希望对你有一定的参考价值。

1.昨天在maven build项目中发现有个问题,如下所示

java.lang.NoSuchMethodError: org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(Lorg/springframework/core/type/AnnotationMetadata;Ljava/lang/Class;Lorg/springframework/core/io/ResourceLoader;Lorg/springframework/core/env/Environment;Lorg/springframework/beans/factory/support/BeanDefinitionRegistry;)V
        at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport$1.<init>(AbstractRepositoryConfigurationSourceSupport.java:68)
        at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.getConfigurationSource(AbstractRepositoryConfigurationSourceSupport.java:67)
        at org.springframework.boot.autoconfigure.data.AbstractRepositoryConfigurationSourceSupport.registerBeanDefinitions(AbstractRepositoryConfigurationSourceSupport.java:58)
        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:320)
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
        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.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
        at com.ppdai.realtime.datachannel.mq.MessageQueueApp.main(MessageQueueApp.java:20)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:558)
        at java.lang.Thread.run(Thread.java:748)

原因分析:

https://github.com/spring-projects/spring-boot/commit/5a4ef50ef1d71f1a42edaee309b3e04fb754b13a

因为spring boot和sping-data-redis版本不匹配导致的,spring-data-redis使用 1.8.1.RELEASE版本  依赖

<dependency>
    <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-keyvalue</artifactId>
    <version>1.2.1.RELEAS</version> 
</dependency>

依赖

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
    <version>1.13.1.RELEASE</version>
</dependency>

如下图所示 这是spring-boot 1.5.9.Release版本的函数

技术分享图片

而spring-data-commons中构造函数如下

技术分享图片

二种解决方案,

第一 将spring-boot-autoconfig版本从1.5.9.RELEASE降低为1.5.2

或者将spring-data-commons版本从1.13.1.RELEASE升到1.13.7.RELEASE

完结。。

另外附上一个问题

Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.config.RepositoryConfigurationSource
Caused by: java.lang.ClassNotFoundException: org.springframework.data.repository.config.RepositoryConfigurationSource
    at java.net.URLClassLoader.findClass (URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass (ClassLoader.java:357)
    at java.lang.Class.getDeclaredConstructors0 (Native Method)
    at java.lang.Class.privateGetDeclaredConstructors (Class.java:2671)
    at java.lang.Class.getConstructor0 (Class.java:3075)
    at java.lang.Class.getDeclaredConstructor (Class.java:2178)
    at org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:102)
    at org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java:125)
    at org.springframework.context.annotation.ConfigurationClassParser.processImports (ConfigurationClassParser.java:585)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass (ConfigurationClassParser.java:293)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass (ConfigurationClassParser.java:244)
    at org.springframework.context.annotation.ConfigurationClassParser.processImports (ConfigurationClassParser.java:595)
    at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors (ConfigurationClassParser.java:538)
    at org.springframework.context.annotation.ConfigurationClassParser.parse (ConfigurationClassParser.java:184)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions (ConfigurationClassPostProcessor.java:308)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry (ConfigurationClassPostProcessor.java:228)
    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.context.embedded.EmbeddedWebApplicationContext.refresh (EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh (SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext (SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run (SpringApplication.java:303)

原因

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration]; nested exception is java.lang.NoClassDefFoundError: org/springframework/data/repository/config/RepositoryConfigurationSource

因为spring-boot autoconfig需要RedisRepositoriesAutoConfiguration  这个类找不到,解决方案

添加依赖

<dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-commons</artifactId>
            <version>1.13.7.RELEASE</version>
</dependency>

因为spring


以上是关于spring-data-redis版本冲突引发的问题的主要内容,如果未能解决你的问题,请参考以下文章

spring-data-redis版本升级2.2.2.RELEASE的问题

redis集群 与spring-data-redis 集成

spring-data-redis读写分离

Maven依赖jar包版本冲突解决方案

spring-data-redis 可以实现消息队列吗

为啥具有对象基础的元类会引发元类冲突?