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

}  

 

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

相关文章:

  • 2021-04-28
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2021-10-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2022-01-17
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案