I want to to implement an audit logging module to my existing system and I want to save actual logged user information and it’s only the httpSession.
I’m using hibernate/spring/struts 2, and in order to get actual logged user information and call saveLog service I need the ServletContext to find those service bean or get the httpServletRequest…
I have been searching and seems binding the session to ThreadLocal usign Filter is the only way? something like this or this (last answer)
is there other suggestion? is this a commun pattern or a good practice ?
Spring can bind current request to the thread out of the box. If you use
DispatcherServlet, it’s done automatically, otherwise you need to declareRequestContextFilter.Then you can access request properties via
RequestContextHolder.