我有一个bean,我最近从一个托管bean转变为一个spring-bean.
Exception e = (Exception) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(
AbstractProcessingFilter.SPRING_Security_LAST_EXCEPTION_KEY);
事情发生了,因为FacesContext.getCurrentInstance()返回null.
是否可以将faces上下文注入我的bean?
最佳答案
is it possible to inject the faces context into my bean?
不确定,但在这种特殊情况下,它不需要. ExternalContext#getSessionMap()
基本上是HttpSession
属性的外观.到了这一点,你只需要以某种方式获取Spring bean中的HttpServletRequest
然后在HttpServletRequest#getSession()
之前从中获取HttpSession.然后你可以在HttpSession#getAttribute()
之前访问会话属性.
我不做Spring,但Google告诉我你可以按如下方式获得它:
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
完成后,您可以这样做:
Exception e = (Exception) request.getSession().getAttribute(AbstractProcessingFilter.SPRING_Security_LAST_EXCEPTION_KEY);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。