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) {  

    }  

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

  • 相关阅读:
    bzoj1066: [SCOI2007]蜥蜴
    bzoj3504: [Cqoi2014]危桥
    bzoj2756: [SCOI2012]奇怪的游戏
    bzoj1570: [JSOI2008]Blue Mary的旅行
    Ultra-QuickSort
    Bin Packing
    Watering Grass
    区间覆盖
    抄书 Copying Books UVa 714
    分馅饼 Pie
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/9572310.html
Copyright © 2011-2022 走看看