8

After configuring spring-session-data-redis in a demo spring-boot project, bootRun task fails with the following message:

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' that could not be found.
    - Bean method 'redisConnectionFactory' not loaded because @ConditionalOnClass did not find required classes 'org.apache.commons.pool2.impl.GenericObjectPool', 'redis.clients.jedis.Jedis'
    - Bean method 'redisConnectionFactory' not loaded because @ConditionalOnClass did not find required class 'io.lettuce.core.RedisClient'

Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactory' in your configuration.

What I've done (a.k.a. steps to reproduce):
1. Used Spring Initializr to create a [Gradle with Java and Spring Boot 2.1.0 M1 + Web dependency] project.
2. Followed the Spring Session - Spring Boot instructions to configure Spring Session. More specifically:
- added compile 'org.springframework.session:spring-session-data-redis' to build.gradle's dependencies block
- configured the store type by adding spring.session.store-type=redis to application.properties file
- configured the connection properties (in application.properties file): spring.redis.host, spring.redis.password and spring.redis.port with relevant values
3. Executed ./gradlew bootRun from the root of the project and received the above error


Questions:
1. As far as I'm understand from the error message, RedisConnectionFactory failed to load because it can't find neither Jedis nor Lettuce drivers. Shouldn't spring-session-data-redis bring one of those drivers by default?
2. How to resolve this issue in case I want to use the Jedis driver?
3. How to resolve this issue in case I want to use the Lettuce driver?

Alex Lipov
  • 13,503
  • 5
  • 64
  • 87
  • 2
    1. No. 2 or 3 include them yourself. The sample uses `spring-boot-starter-data-redis` as well, this pulls in a driver by default. – M. Deinum Aug 08 '18 at 10:15
  • @M.Deinum Thanks. The guide itself doesn't mention `spring-boot-starter-data-redis`, nor explicit driver dependency. Also, it seems that this is a behavior change - I'm able to run `bootRun` using spring-boot's `1.5.16.BUILD-SNAPSHOT` version flawlessly without explicit driver dependency. – Alex Lipov Aug 08 '18 at 10:58
  • 2
    The instruction are incorrect and are out of sync with the sample application to which they link. It [has a dependency on spring-boot-starter-data-redis](https://github.com/spring-projects/spring-session/blob/master/samples/boot/redis/spring-session-sample-boot-redis.gradle#L8). – Andy Wilkinson Aug 08 '18 at 11:27
  • @AndyWilkinson Thanks. Is there a recommended way for pulling the Lettuce driver in: implicitly by adding `spring-boot-starter-data-redis` dependency, or explicitly by adding `io.lettuce:lettuce-core` dependency? – Alex Lipov Aug 08 '18 at 11:39
  • 2
    I would use the starter. – Andy Wilkinson Aug 08 '18 at 12:39

2 Answers2

14

1.
As @M.Deinum mentioned, spring-session-data-redis (version 2.1.0.M1) doesn't pull Jedis or Lettuce drivers.

2.
Add the latest Jedis driver as explicit dependency:

dependencies {  
    // ...  
    compile 'redis.clients:jedis:2.9.0'  
} 

3.
Either add spring-boot-starter-data-redis (which pulls in Lettuce driver) or the latest Lettuce driver as explicit dependency:

dependencies {  
    // ...  
    compile 'org.springframework.boot:spring-boot-starter-data-redis'  
    // OR
    compile 'io.lettuce:lettuce-core:5.0.5.RELEASE' 
} 
Alex Lipov
  • 13,503
  • 5
  • 64
  • 87
2

There is 2 implementation of RedisConnectionFactory are comes with spring-session-data-redis

(1) lettuce (default) - https://github.com/spring-projects/spring-session/issues/789

(2) Jedis

Since lettuce & Jedis dependency are optional u have to have explicit dependency. u can put dependency to either one of it. (u can have both but Spring redis implementation stater used lettuce as a default implementation)

Example:

    <dependency>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
        <version>x.x.x</version>
    </dependency>
    <dependency>
        <groupId>io.lettuce</groupId>
        <artifactId>lettuce-core</artifactId>
        <version>x.x.x</version>
    </dependency>
qiAlex
  • 4,290
  • 2
  • 19
  • 35