@EventListener简单描述

简化我们编写监听类的步骤,不需要再继承ApplicationListener接口去实现onApplicationEvent了。

 

例子:

@Component
public class TestEventListener {
    @EventListener(classes = {ApplicationEvent.class})
    public void testEvent(ApplicationEvent event){
        System.out.println("done---->"+event.toString());
    }

//     直接在方法里面进行指定也是可以的。不需要再注解里面设置
//    @EventListener()
//    public void testEvent(ApplicationEvent event){
//        System.out.println("done---->"+event.toString());
//    }

    @EventListener()
    public void testEvent2(ApplicationStartedEvent event){
        System.out.println("done--Even2-->"+event.toString());
    }
}

运行结果:

springboot-@EventListener简单用法

 

相关文章:

  • 2021-12-06
  • 2021-04-12
  • 2022-12-23
  • 2022-12-23
  • 2021-05-04
  • 2022-12-23
  • 2021-08-03
  • 2021-04-05
猜你喜欢
  • 2021-12-18
  • 2021-08-22
  • 2021-09-13
  • 2021-07-06
  • 2022-01-23
  • 2021-09-21
相关资源
相似解决方案