网站的程序有哪些内容,如何查询网站接入信息,有哪些网站是flash型,人工智能培训机构排名一、简介
ApplicationEventPublisher是简称为Spring中的事件发布器#xff0c;应用于Java事件型驱动应用是解耦和设计#xff0c;Spring对Java已有的事件处理模型#xff0c;做了进一步的简化处理。
二、发布及处理事件
ApplicationEventPublisher是一个函数式编程的接口…一、简介
ApplicationEventPublisher是简称为Spring中的事件发布器应用于Java事件型驱动应用是解耦和设计Spring对Java已有的事件处理模型做了进一步的简化处理。
二、发布及处理事件
ApplicationEventPublisher是一个函数式编程的接口里面有两个方法主要用来发布事件后续消费事件即可通过EventListener注解进行消费即可。 发布者会调用 ApplicationEventPublisher的publishEvent 方法对某一事件进行发布。随后Spring容器会把该事件告诉所有的监听者监听者根据拿到的“信息、某些指令或者某些数据”去做一些业务上的操作。
2.1 发布事件
通过ApplicationEventPublisher 的publishEvent进行事件的发布 Autowiredprivate ApplicationEventPublisher publisher;private void publishDTO(JSONObject data) {Cs001DTO dto JSONObject.toJavaObject(data, Cs001DTO.class);//发布事件publisher.publishEvent(dto);}2.2 提取工具类
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;Slf4j
Component
public class EventUtil {/*** 应用事件发布*/public static ApplicationEventPublisher publisher;Autowiredpublic void setPublisher(ApplicationEventPublisher publisher) {EventUtil.publisher publisher;}/*** 同步推送** param event 触发事件*/public static void pushSynEvent(Object event) {try {log.debug(同步发布事件 Class:{}, event.getClass().getName());publisher.publishEvent(event);} catch (Exception e) {log.error(同步发布事件错误 {}, JsonUtil.toJSONString(event), e);}}
}三、总结
本篇简单介绍Spring的时间发布器ApplicationEventPublisher的使用。