Unable to start spring-boot application after configuring spring-session-data-redis
Clash Royale CLAN TAG#URR8PPP
Unable to start spring-boot application after configuring spring-session-data-redis
After configuring spring-session-data-redis
in a demo spring-boot project, bootRun
task fails with the following message:
spring-session-data-redis
bootRun
***************************
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
compile 'org.springframework.session:spring-session-data-redis'
spring.session.store-type=redis
application.properties
application.properties
spring.redis.host
spring.redis.password
spring.redis.port
./gradlew bootRun
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?
RedisConnectionFactory
spring-session-data-redis
spring-boot-starter-data-redis
@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 8 at 10:58
spring-boot-starter-data-redis
bootRun
1.5.16.BUILD-SNAPSHOT
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.
– Andy Wilkinson
Aug 8 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 8 at 11:39
spring-boot-starter-data-redis
io.lettuce:lettuce-core
I would use the starter.
– Andy Wilkinson
Aug 8 at 12:39
1 Answer
1
1.
As @M.Deinum mentioned, spring-session-data-redis
(version 2.1.0.M1) doesn't pull Jedis or Lettuce drivers.
spring-session-data-redis
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:
spring-boot-starter-data-redis
dependencies
// ...
compile 'org.springframework.boot:spring-boot-starter-data-redis'
// OR
compile 'io.lettuce:lettuce-core:5.0.5.RELEASE'
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
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 8 at 10:15