springBoot 自定义监听器的几种方式

 

springBoot 自定义监听器的几种方式_第1张图片

 

第一种:在初始化的时候添加监听器 app.addListeners(new MyApplicationListener());

第二种:

springBoot 自定义监听器的几种方式_第2张图片

第三种:在application.propertiies 添加

context.listener.classes=com.boot.enable.addlistener.MyApplicationListener

第四种:

@Component
public class HandlerEvent {

    @EventListener
    public void evendListener(MyApplicationEvent event){
        System.out.println("监听了-----"+event.getSource());
        System.out.println("监听了-----"+event.getClass());
    }

}

你可能感兴趣的:(spring,springboot)