springboot监听器的使用

2019-07-12 15:58:00
admin
原创
15
摘要:springboot监听器的使用

springboot监听器的使用

首先注册一个事件,其中MessageEntity为我自己的实体

public class JpushEvent extends ApplicationEvent {
    private MessageEntity messageEntity;
    public JpushEvent(Object source, MessageEntity messageEntity) {
        super(source);
        this.messageEntity=messageEntity;
    }
    public MessageEntity getMessageEntity(){
        return this.messageEntity;
    }
}

二、事件的监听

@Component
public class JpushEventListener{
    private Logger logger= LoggerFactory.getLogger(JpushEventListener.class);
    @EventListener
    @Async
    public void event(JpushEvent jpushEvent) throws InterruptedException {
logger.info("######事件监听开始时间####"+jpushEvent.getTimestamp());
        MessageEntity entity=jpushEvent.getMessageEntity();
}
三、事件的发不

@Autowired
   private ApplicationEventPublisher publisher;
publisher.publishEvent(new JpushEvent(this, new MessageEntity(userId, "88888", "team", null)));

发表评论
评论通过审核之后才会显示。
文章分类
联系方式
联系人: 郑州-小万
电话: 13803993919
Email: 1027060531@qq.com
QQ: 1027060531
网址: www.wanhejia.com