我正在开发一个使用 Spring Security 进行验证的 spring MVC 应用程序。我想在登录后做一些工作,并且在多个地方(包括 enter link description here )看到了使用应用程序监听器实现此目的的建议。我已经继续实现它了:
@Named
public class AccountLoginListener implements ApplicationListener<AuthenticationSuccessEvent> {
@Inject
AccountService accountService;
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
Account account = (Account) event.getAuthentication().getDetails();
...
accountService.saveAccount(account);
}
}
不幸的是,AuthenticationSuccessEvent 似乎没有被捕获,而且当我调试时,onApplicationEvent 函数从未被调用。我没有在 xml 文件中做任何额外的配置,但我认为没有必要这样做。我是否缺少某些配置,或者我做错了什么?
谢谢!
伊本特利
最佳答案
如果你使用的是 Spring Security 3,你应该实现 AuthenticationSuccessHandler
,然后在您的应用程序上下文中配置此 bean。
关于java - 应用程序监听器未收到事件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6073717/