2011-06-30 15 views
0

我无法在我的自定义成功处理程序注入弹簧会话bean:如何在自定义的春季安全登录成功处理程序注入会话bean

@Component 
public class CustomSavedRequestAwareAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { 

    @Resource 
    private SessionController sessionController; 

    @Override 
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { 
     super.onAuthenticationSuccess(request, response, authentication); 
     sessionController.setUtenteOnline(); 
    } 

上sessionController返回一个空指针异常。 预先感谢您

+1

你是不是想要使用@Autowire? –

+0

它也不适用于@Autowired –

+2

你是什么意思的“春季会议bean”? – skaffman

回答

1

您的成功处理程序可能是一个单身人士,所以你只能将singletons可靠地注入它。你可以使用scoped dependencies来解决这个问题。基本上,它涉及Spring注入一个单例动态代理,它管理从会话范围获取实际bean并将调用委托给它。

+0

感谢您的回答,但此时我没有时间来测试您的解决方案。我已经做了一个工作,但我相信我会再次需要这个功能。 –