Learn how to solve the problem of lost sessions using Redis and Spring Session.
- Why in-memory sessions break in production
- How to configure Spring Session with Redis
- How sessions persist across application restarts
cd java-springboot/workshop-hub
# Start the hub, Redis, and workshop 1
docker compose -f docker-compose.local.yml --profile infrastructure up -d
docker compose -f docker-compose.local.yml --profile workshop-1_session_management up -dOpen http://localhost:9000 and launch the Session Management workshop from the Hub.
Login: user / password
| Stage | What You Do |
|---|---|
| 1. See the Problem | Login, restart the workshop backend, observe session loss |
| 2. Fix It | Update the 3 editable files listed below |
| 3. Verify | Rebuild and restart the workshop backend, then confirm the session survives |
Uncomment the Redis dependencies:
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation("org.springframework.session:spring-session-data-redis")Enable Redis-backed session storage:
spring.session.store-type=redis
spring.session.redis.namespace=spring:session
spring.session.redis.flush-mode=immediate
spring.session.redis.repository-type=defaultUncomment the HttpSessionSecurityContextRepository import, the SecurityContextRepository bean, and the securityContext(...) filter-chain wiring.
- Log in and note the current session ID.
- Restart the workshop backend from the Hub without rebuilding and confirm the session is lost.
- Make the three code changes above.
- Rebuild and restart the workshop backend from the Hub.
- Refresh the workshop and confirm you stay logged in with the same session ID.
Use the Open Redis Insight action inside the workshop, or open http://localhost:5540 directly.
Search for:
spring:session:*
docker compose -f docker-compose.local.yml --profile workshop-1_session_management down