Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2203

Inconsistent Session Retrieval in Legacy Spring MVC App: Redis vs. Tomcat HttpSession

$
0
0

I'm encountering an inconsistency in session retrieval within my legacy Spring MVC 5 application deployed on Tomcat 9. Specifically, I'm observing different behaviors when retrieving sessions using RequestContextHolder based on whether the session is managed by Redis or Tomcat's HttpSession.

Here's a breakdown of the issue:

Redis Session Management:

  • Implemented Spring Session with Redis for session management using @EnableRedisHttpSession.
  • Configured a RedisSessionConfig class to define the Redis connection factory using Lettuce.
  • Verified successful connection to Redis and configured Spring MVC to use Redis for session management.

Tomcat HttpSession:

Default session management provided by Tomcat's HttpSession.

Observations:

  • When obtaining the session object using HttpServletRequest.getSession(), it consistently returns the Redis-backed session object, indicating that Redis-based session management is being used.
  • However, when attempting to retrieve the session using RequestContextHolder, the behavior is inconsistent:RequestContextHolder.getRequestAttributes().getRequest().getSession() consistently returns the Tomcat HttpSession object.There is no observed instance of ServletRequestAttributes containing the Redis session object when using RequestContextHolder.

Desired Outcome:

  • Ensure consistent session retrieval behavior across the application, regardless of whether the session is managed by Redis or Tomcat.
  • Understand the reasons behind the inconsistency observed when using RequestContextHolder to obtain sessions.
  • Determine if there are specific configurations or best practices to follow to ensure reliable session management with Redis in a legacy Spring MVC application deployed on Tomcat 9.

Has anyone encountered similar issues with session retrieval in legacy Spring MVC applications using Redis and Tomcat's default HttpSession? How can I ensure consistent session management and retrieval behavior across the application?

Any insights, suggestions, or guidance would be greatly appreciated. Thank you!


Viewing all articles
Browse latest Browse all 2203

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>