2011-06-30 14 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

感謝您的回答,但此時我沒有時間來測試您的解決方案。我已經做了一個工作,但我相信我會再次需要這個功能。 –