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

    }  

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

  • 相关阅读:
    TCL 双引号和花括号的区别
    在Vivado中调用ModelSim生成FSM的状态转移图
    基于配置文件的方式来配置AOP
    Spring MVC_Hello World
    重用切点表达式
    Spring MVC概述(2)
    Shiro_DelegatingFilterProxy
    Shiro-工作流程
    切面的优先级
    Shiro-集成Spring
  • 原文地址:https://www.cnblogs.com/tyoyi/p/8028717.html
Copyright © 2020-2023  润新知