skip to Main Content

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?

Many thanks for any help

2

Answers


  1. Chosen as BEST ANSWER

    So after more than one hour spending valuable time in figuring out what the problem could be, I found in a youtube video the following dependency added rather casually:

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

    Well, since the dependency to this package is never mentioned in the Spring Boot documentations anywhere, I wonder: are developers supposed to be crystall ball eyed fortune tellers in their second job? How the fuck shall I know that this is a major required dependency?

    If you'd sum up all the senseless hours spent by developers figuring out how to get things working just because the docs are crap, I think you'd get to millions a month. Nothing more to say...


  2. "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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search