第一种:在初始化的时候添加监听器 app.addListeners(new MyApplicationListener());
第二种:
第三种:在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()); } }