spring 事件机制demo
来源:互联网 发布:mac口红国内专柜价格表 编辑:程序博客网 时间:2024/06/03 20:18
理论知识不多讲,自行度娘。直接上代码,如下。
package com.ai.runner.dmp.service.event;import org.springframework.context.ApplicationEvent;/** * @author xuyw * @version V1.0 * @Description: * @date 2017-09-11 下午 2:01 */public class DmpEvent extends ApplicationEvent { private static final long serialVersionUID = 1L; /** * 发送事件类型 */ private EventEnum eventType; /** * 发送的消息可发送json字符串 */ private String msg; public DmpEvent(Object source, EventEnum eventType, String msg) { super(source); this.eventType = eventType; this.msg = msg; } public EventEnum getEventType() { return eventType; } public void setEventType(EventEnum eventType) { this.eventType = eventType; } public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public static enum EventEnum { BIND_EQU("绑定设备"), UNBIND_EQU("解绑设备"); EventEnum(String desc) { this.desc = desc; } private String desc; public String getDesc() { return desc; } public void setDesc(String desc) { this.desc = desc; } }}
package com.ai.runner.dmp.service.event;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import com.ai.opt.sdk.util.CollectionUtil;
import com.ai.runner.dmp.dao.mapper.bo.TEquUserRel;
import com.ai.runner.dmp.service.atom.interfaces.ITEquUserRelAtomSV;
import com.ai.runner.dmp.service.atom.interfaces.ITEquipmentAtomSV;
/**
* @author xuyw
* @version V1.0
* @Description:
* @date 2017-09-11 下午 2:09
*/
@Component
public class DmpListener implements ApplicationListener {
private static final Logger LOG = LogManager.getLogger(DmpListener.class);
@Autowired
ITEquipmentAtomSV iTEquipmentAtomSV;
@Autowired
ITEquUserRelAtomSV iTEquUserRelAtomSV;
@Override//@Asyncpublic void onApplicationEvent(DmpEvent event) { DmpEvent.EventEnum eventType = event.getEventType(); String msg = event.getMsg(); LOG.info("DmpListener收到事件监听:-->"); LOG.info("事件类型:" + eventType.getDesc()); LOG.info("事件内容:" + msg); switch (eventType) { case BIND_EQU: iTEquipmentAtomSV.updateEquBindStatus(msg, "1"); break; case UNBIND_EQU: List<TEquUserRel> list = iTEquUserRelAtomSV .queryEquUserRelByImei(msg); if (CollectionUtil.isEmpty(list)) { // 没有绑定的设备 iTEquipmentAtomSV.updateEquBindStatus(msg, "0"); } break; }}
}
package com.ai.runner.dmp.service.event;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.ApplicationContext;import org.springframework.stereotype.Component;/** * @author xuyw * @version V1.0 * @Description: * @date 2017-09-11 下午 1:56 */@Componentpublic class DmpPublisher { @Autowired ApplicationContext applicationContext; public void publishDmpEvent(DmpEvent.EventEnum eventType, String msg){ applicationContext.publishEvent(new DmpEvent(this,eventType,msg)); }}
- spring 事件机制demo
- spring中事件机制
- spring的事件机制
- Spring事件机制
- Spring ApplicationContext事件机制
- Spring事件机制
- spring 事件机制
- spring中的事件机制
- 二,Spring事件机制
- spring的事件机制
- Spring-ApplicationContext事件机制
- Spring 事件机制
- Spring ApplicationContext事件机制
- Android Touch事件传递机制解析+demo
- Android事件分发机制(Demo测试)
- Spring事件机制项目应用
- spring容器的事件机制
- Spring---ApplicationContext的事件机制
- hibernate注解排序@orderBy
- spring AOP 3种方式
- Android 关于WebView全方面的使用
- Java(8-5)阻塞队列与线程安全集合
- CryptoNight
- spring 事件机制demo
- SpringBoot~整合mybatis+微服务注册
- java-Thread线程安全
- 使用wok kimchi插件管理kvm(编译安装)
- 二代测序call indel 总结
- Log4j记录日志
- charles入门教程
- .NET、JAVA和PHP在Web开发的优缺点
- 解决android中icon只能使用一张icon的问题