首先,类的写法
public class InvestEvent extends ApplicationEvent{
private static final long serialVersionUID = 1L;
public InvestEvent(Object source) {
super(source);
}
}
@Listener(order = 2, enableAsync = true)
public class BonusListener implements ApplicationListener<InvestEvent>{
@Override
public void onApplicationEvent(InvestEvent event) {
ProjectDetail project = (ProjectDetail) event.getSource();
System.out.println("11111111111111");
}
注意,写完类之后必须在config当中进行配置插件,否则eventkit插件为null
// 初始化插件
EventPlugin eventPlugin = new EventPlugin();
// 开启全局异步
eventPlugin.async();
// 设置监听器默认包,默认全扫描
eventPlugin.scanPackage("com.......");
me.add(eventPlugin);
之前就是没有在config中配置,导致事件一直发布成功