据我所知,
ApplicationListener实例只是您中的bean
ApplicationContext。因此,您应该能够将其他bean或资源注入其中。
因此,要获得对当前
HttpSession实例的引用:
public class AuthenticationSuccessListener implements ApplicationListener<InteractiveAuthenticationSuccessEvent> {@Autowiredprivate HttpSession httpSession; @Override public void onApplicationEvent(InteractiveAuthenticationSuccessEvent e) { //adding object to HttpSession }}Spring将
HttpSession使用其作用域代理机制注入,以确保您
HTTPSession与当前执行线程相关。
您还需要确保
RequestContextListener在web.xml中注册一个,以便Spring可以注入当前的
HTTPSession。
<listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>



