我无法在自定义成功处理程序中注入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上返回空指针异常。 提前谢谢
答案 0 :(得分:1)
你的成功处理程序可能是一个单例,所以你只能可靠地将单例注入其中。您可以使用scoped dependencies解决此问题。基本上,它涉及Spring注入一个单独的动态代理,该代理管理从会话范围获取真实bean并将调用委托给它。