如何在自定义spring安全登录成功处理程序中注入会话bean

如何在自定义spring安全登录成功处理程序中注入会话bean,spring,session,login,spring-security,Spring,Session,Login,Spring Security,我无法在自定义成功处理程序中注入spring会话bean: @Component public class CustomSavedRequestAwareAuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { @Resource private SessionController sessionController; @Override publi

我无法在自定义成功处理程序中注入spring会话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上返回空指针异常。
提前感谢您

您的成功处理程序可能是单例,因此您只能可靠地将单例注入其中。您可以使用。基本上,它涉及到Spring注入一个单例动态代理,该代理管理从会话作用域获取真正的bean并将调用委派给它。

你不是想使用@Autowire吗?它与@Autowired也不起作用你说的“Spring会话bean”是什么意思?Spring管理的作用域(“会话”)bean。谢谢你的回答,但是现在我没有时间测试你的解决方案。我已经做了一轮训练,但我相信我还需要这个功能。