zoukankan      html  css  js  c++  java
  • Spring @EventListener 异步中使用condition的问题

    @EventListener是spring在4.2+推出的更好的使用spring事件架构的方式,并且异步方式也很好设定

    但是在spring4.2.7版本上使用eventlistener的condition 的使用需要注意以下情况可能失效:

    condition 使用例子如@EventListener(condition = "#event.isAsync")

    1. 需要对同一个事件进行区分同步异步

    2. 使用condition来进行过滤

    例如:需要对事件用condition进行区分同步异步

    @Async

    @EventListener(condition = "#event.isAsync")

    public void handleOrderCreatedEventAsync(TestEvent event) {  

    }  

    @EventListener(condition = "#event.isAsync == false")

    public void handleOrderCreatedEvent(TestEvent event) {  

    }  

    修正的做法,是使用两个事件区分即:

    @Async

    @EventListener

    public void handleOrderCreatedEventAsync(TestEventAsync event) {  

    }  

    @EventListener

    public void handleOrderCreatedEvent(TestEvent event) {  

    }  

    还不清楚,在更高的版本上是否已经有进一步的修正,待以后研究

  • 相关阅读:
    Bugs及解决方案列表
    CSS技巧和经验
    我的越权之道
    密码找回逻辑漏洞总结
    业务安全漏洞挖掘归纳总结【转载】
    User Agent
    影响网站页面打开速度的三个因素
    iframe 透明
    ie对行高line-height的诡异解释
    A标记点击后去掉虚线
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/9572310.html
Copyright © 2011-2022 走看看