zoukankan      html  css  js  c++  java
  • spring event 事件

    事件流程

    1发布事件 ApplicationEventPublisherAware

    2监控事件 ApplicationListener

    3.生成事件 applicationEvent

    发布事件

    package com.example.demo.qin;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.ApplicationEventPublisher;
    import org.springframework.context.ApplicationEventPublisherAware;
    import org.springframework.stereotype.Component;
    
    /**
     * @program: springboot_test
     * @description: 事件发布
     * @author: Mr.qin
     * @create: 2018-12-19 06:14
     **/
    @Component
    public class EventPublish implements ApplicationEventPublisherAware {
        @Autowired
        private  ApplicationEventPublisher applicationEventPublisher;
    
        public void publish(EventTest event){
            applicationEventPublisher.publishEvent(event);
        }
    
        @Override
        public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
            this.applicationEventPublisher=applicationEventPublisher;
        }
    }
    

    监控事件

    package com.example.demo.qin;
    
    import org.springframework.context.ApplicationListener;
    import org.springframework.stereotype.Component;
    
    /**
     * @program: springboot_test
     * @description: 事件监听
     * @author: Mr.qin
     * @create: 2018-12-19 05:38
     **/
    @Component
    public class EventRelease implements ApplicationListener<EventTest> {
        @Override
        public void onApplicationEvent(EventTest event) {
            System.out.println("更新失败回,删除插入信息"+event.getEventStr()+event.getSource());
        }
    }
    

      

     生成事件

    package com.example.demo.qin;
    
    import org.springframework.context.ApplicationListener;
    import org.springframework.stereotype.Component;
    
    /**
     * @program: springboot_test
     * @description: 事件监听
     * @author: Mr.qin
     * @create: 2018-12-19 05:38
     **/
    @Component
    public class EventRelease implements ApplicationListener<EventTest> {
        @Override
        public void onApplicationEvent(EventTest event) {
            System.out.println("更新失败回,删除插入信息"+event.getEventStr()+event.getSource());
        }
    }
     
    

      

  • 相关阅读:
    jQuery动态效果
    10.嗖嗖移动业务大厅
    10.IDEAD 的xml中配置DTD
    浏览器缓存相关的Http头介绍:Expires,Cache-Control,Last-Modified,ETag
    nginx 重启
    fiddler 路由设置
    JavaScript Source Map 详解
    xdebug.var_display_max_data
    PHP输出当前进程所有变量 / 常量 / 模块 / 函数 / 类
    PHP中文件包含的路径问题
  • 原文地址:https://www.cnblogs.com/qin-up/p/10141536.html
Copyright © 2011-2022 走看看