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?
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'
}
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With