Following this example here I upgraded my Spring Boot 3.2 application to use Redis as session storage.
I've added the required dependency:
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
</dependency>
I've set some application properties (yaml):
spring.session.redis.flush-mode: on_save
spring.session.redis.namespace: "spring:session"
spring.data.redis.host: "localhost"
spring.data.redis.port: 6379
And I have a Redis server running which is connectable on "127.0.0.1:6379". I can add keys via redis-cli
so I know, Redis is ok.
However, when I search the Redis database I won't get any keys related to Spring Session. Since authentication works I assume that the sessions are still managed by Tomcat itself.
According to the Spring Session Configuration Documentation there should be a springSessionRepositoryFilter
bean created, but this bean is not configured. Also, there is no RedisConnectionFactory
in the context.
FYI: When using spring-session-jdbc
instead the sessions are stored inside the JDBC database as expected.
Does anybody know why Spring Session won't set up Redis for storage although I followed the documentation step by step? Do I need to add some additional configurations which aren't mentioned in the documentation?
"spring-session-data-redis" need to use the redis client such as Lettuce. It's dependency paths to client are as follows:
spring-session-data-redis
->spring-data-redis
->lettuce-core(<optional>true</optional>)
.
Maven will not auto import lettuce when you add spring-session-data-redis
, since the optional is true. You need to add spring-boot-starter-data-redis
or lettuce-core
in your pom.xml.