java - 应用程序监听器未收到事件通知

标签 java spring spring-mvc spring-security listener

我正在开发一个使用 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/

相关文章:

java - Tomcat7 使用 APR 连接器启用 tlsv1.1

Java 错误 - "invalid method declaration; return type required"

java - 如何模拟OutOfMemoryError : Metaspace

spring - Spring RMI 出现错误

java - Spring MVC 在带点的 URL 上返回 HTTP 406

java - Spring : PropertyPlaceholderConfigurer cannot find property file

spring-mvc - 从 WebApplicationContext 创建 MockMvc 和从 Controller 实例创建 MockMvc 之间的区别?

java - 线程循环 - 扩展 Thread 类 Java

java - java中如何获取文件的绝对路径

css - 带有整个 html 模板的 spring mvc