Cannot get connection for redisTemplate for Spring data redis

后端 未结 10 2021
太阳男子
太阳男子 2020-12-05 21:25

I\'m trying to publish a message to a channel using Spring data Redis using Jedis. Here is a very simple Java config:

@Bean(name=\"jedisConnectionFactory\")
         


        
相关标签:
10条回答
  • 2020-12-05 21:39

    Compatible version:

    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>1.5.0.RELEASE</version>
    </dependency>
    
    0 讨论(0)
  • 2020-12-05 21:40

    This issue is caused by the Jedis version (2.7.2) not compatible with Spring Data Redis (1.5.0.RELEASE). I used 3 days facing the same issue before I get inspired by this post and comment. Jedis version (2.6.2) is working fine (although I hit other errors in my program, but at least it have some progress than the same error message)!

    Thanks.

    0 讨论(0)
  • 2020-12-05 21:48

    You can find spring data maven version compatible with jedis maven version from bellow link: https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis/1.5.9.RELEASE

    0 讨论(0)
  • 2020-12-05 21:49

    I have also faced a similar kind of issue. I did some research and found out that it is due to a jar conflict.

    Compatible version i am using in my application is :

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-redis</artifactId>
        <version>1.8.10.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>2.9.0</version>
    </dependency>
    

    Or if you are using spring boot simply add the following dependency. Spring boot is smart enough to auto resolve such issues.

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
    </dependency>
    

    I hope it helps !!

    0 讨论(0)
  • 2020-12-05 21:49

    Version, I encountered the same problem,this spring-data-redis 1.5.0 pom

    <?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.springframework.data</groupId>
      <artifactId>spring-data-redis</artifactId>
      <version>1.5.0.RELEASE</version>
      <name>Spring Data Redis</name>
      <description>Spring Data Redis</description>
      <url>http://github.com/spring-projects/spring-data-redis</url>
      <organization>
        <name>Pivotal Software, Inc.</name>
        <url>http://projects.spring.io/spring-data-redis</url>
      </organization>
      <licenses>
        <license>
          <name>The Apache Software License, Version 2.0</name>
          <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
          <distribution>repo</distribution>
        </license>
      </licenses>
      <developers>
        <developer>
          <id>costin</id>
          <name>Costin Leau</name>
          <email>cleau@vmware.com</email>
          <properties>
            <twitter>costinl</twitter>
          </properties>
        </developer>
        <developer>
          <id>jencompgeek</id>
          <name>Jennifer Hickey</name>
          <properties>
            <twitter>jencompgeek</twitter>
          </properties>
        </developer>
        <developer>
          <id>christophstrobl</id>
          <name>Christoph Strobl</name>
          <properties>
            <twitter>stroblchristoph</twitter>
          </properties>
        </developer>
        <developer>
          <id>thomasdarimont</id>
          <name>Thomas Darimont</name>
          <properties>
            <twitter>thomasdarimont</twitter>
          </properties>
        </developer>
      </developers>
      <scm>
        <connection>scm:git:git://github.com/spring-projects/spring-data-redis</connection>
        <developerConnection>scm:git:git://github.com/spring-projects/spring-data-redis</developerConnection>
        <url>http://github.com/spring-projects/spring-data-redis</url>
      </scm>
      <dependencies>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-oxm</artifactId>
          <version>4.0.9.RELEASE</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>4.0.9.RELEASE</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-mapper-asl</artifactId>
          <version>1.8.8</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context-support</artifactId>
          <version>4.0.9.RELEASE</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-tx</artifactId>
          <version>4.0.9.RELEASE</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.jredis</groupId>
          <artifactId>jredis-core-ri</artifactId>
          <version>06052013</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>redis.clients</groupId>
          <artifactId>jedis</artifactId>
          <version>2.6.2</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-aop</artifactId>
          <version>4.0.9.RELEASE</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-core</artifactId>
          <version>4.0.9.RELEASE</version>
          <scope>compile</scope>
          <exclusions>
            <exclusion>
              <artifactId>commons-logging</artifactId>
              <groupId>commons-logging</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>commons-beanutils</groupId>
          <artifactId>commons-beanutils-core</artifactId>
          <version>1.8.3</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-pool2</artifactId>
          <version>2.2</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>com.github.spullara.redis</groupId>
          <artifactId>client</artifactId>
          <version>0.7</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
          <version>2.5.1</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>1.7.10</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.lambdaworks</groupId>
          <artifactId>lettuce</artifactId>
          <version>2.3.3</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>org.jredis</groupId>
          <artifactId>jredis-core-api</artifactId>
          <version>06052013</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
        <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-core</artifactId>
          <version>2.5.1</version>
          <scope>compile</scope>
          <optional>true</optional>
        </dependency>
      </dependencies>
    </project>
    
    0 讨论(0)
  • 2020-12-05 21:52

    For those using Spring-boot-starter-data-redis

    A permanent fix can be entered as follows:

    1. Determine the version of spring-boot-starter-data-redis. In eclipse, you can mouse over the dependency entry in your pom.xml file. It will tell you the version you are using.
    2. Navigate to that version directory in your maven repository.
    3. Edit the pom file and add the version number of redis client that is needed. In this case version 2.6.2.RELEASE to go with version 1.50 of spring-boot-starter-data-redis. In this case I had to add <version>2.6.2.RELEASE</version.
    4. In your IDE, refresh your entire project. To do this in eclipse or STS, click once on the project name->right click select maven->Update Project
    5. Check your maven dependencies list and the jedis version should now be 2.6.2.
    6. Compile your project.
    7. Open the .war archive with jar or 7-zip etc. Find the lib directory under WEB-INF and verify the presence of jedis-2.6.2.

    That should resolve the issue.

    0 讨论(0)
提交回复
热议问题