如何在AuthenticationSuccessHandler中检索会话范围的bean?
我有一个自定义AuthenticationSuccessHandler。
我想要做的是在onAuthenticationSuccess方法中设置一些会话数据。
要存储会话数据,我想使用会话范围的bean,它可以在任何控制器中正常工作。
但是如果我尝试在onAuthenticationSuccess方法中检索它,我会得到一个例外:
创建名为’scopedTarget.sessionData’的bean时出错:当前线程的作用域’session’无效;
我的代码是:
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext()); SessionData sessionData = context.getBean(SessionData.class);
有任何想法吗?
您可以尝试声明一个暴露实现会话范围所必需的状态的侦听器:
org.springframework.web.context.request.RequestContextListener
默认情况下, DispatcherServlet
公开该状态,因此在请求进入DispatcherServlet
之前它不可用(例如,在Spring Securityfilter中)。
- Guice代理支持循环依赖
- Jersey2,Hk2dependency injection(自动)给出AbstractMethodError:org.jvnet.hk2.internal.DynamicConfigurationImpl.addIdempotentFilter
- OpenEJB本地客户端注入失败
- 在websphere共享库中使用CDI
- HK2没有用jersey注入HttpServletRequest
- 为什么Spring的@Configurable有时可以工作,有时候不工作?
- Java / Jersey – 使用ParamInjectionResolver创建自己的注入解析器 – 奇怪的行为
- 如何在Spring中使用@ComponentScan懒洋洋地加载所有bean?
- Spring ServiceLocator还是纯工厂模式?