开发者

How to get web session on Spring AOP

开发者 https://www.devze.com 2023-01-17 22:25 出处:网络
I have a question for using Spring AspectJ. I want to create an audit log when the user does som开发者_运维问答ething and get user information from web session to create the audit log.

I have a question for using Spring AspectJ. I want to create an audit log when the user does som开发者_运维问答ething and get user information from web session to create the audit log. Can anyone provide examples of how to do this?


Spring MVC's DispatcherServlet stores request in a thread-local variable (if you don't use Spring MVC, you may declare RequestContextListener in web.xml to do the same thing). This variable can be accessed via RequestContextHolder:

HttpSession s = (HttpSession) RequestContextHolder
                    .currentRequestAttributes()
                    .resolveReference(RequestAttributes.REFERENCE_SESSION);
0

精彩评论

暂无评论...
验证码 换一张
取 消