Spring Transaction#TransactionalEventListener
来源:互联网 发布:python的multiply函数 编辑:程序博客网 时间:2024/06/06 04:31
TransactionalEventListener本质上是一个@EventListener,Spring Tx针对使用Transaction时进行了贴别的处理;处理过程可见ApplicationListenerMethodTransactionalAdapter;
在TransactionalEventListener中可以配置一个TransactionPhase参数;ApplicationListenerMethodTransactionalAdapter的处理流程就是为所有带TransactionalEventListener注解的方法创建一个ApplicationListenerMethodTransactionalAdapter对象,然后放到Spring ApplicationContext中;
在ApplicationListenerMethodTransactionalAdapter中会处理TransactionalEventListener注解的信息,将EventListener标识的方法的执行时机与jta中的Synchronization绑定在一起;绑定操作是通过实现了Spring Tx TransactionSynchronizationAdapter类的TransactionSynchronizationEventAdapter类来实现的;
下面是此类的实现:
private static class TransactionSynchronizationEventAdapter extends TransactionSynchronizationAdapter { private final ApplicationListenerMethodAdapter listener; private final ApplicationEvent event; private final TransactionPhase phase; public TransactionSynchronizationEventAdapter(ApplicationListenerMethodAdapter listener, ApplicationEvent event, TransactionPhase phase) { this.listener = listener; this.event = event; this.phase = phase; } @Override public int getOrder() { return this.listener.getOrder(); } @Override public void beforeCommit(boolean readOnly) { if (this.phase == TransactionPhase.BEFORE_COMMIT) { processEvent(); } } @Override public void afterCompletion(int status) { if (this.phase == TransactionPhase.AFTER_COMMIT && status == STATUS_COMMITTED) { processEvent(); } else if (this.phase == TransactionPhase.AFTER_ROLLBACK && status == STATUS_ROLLED_BACK) { processEvent(); } else if (this.phase == TransactionPhase.AFTER_COMPLETION) { processEvent(); } } protected void processEvent() { this.listener.processEvent(this.event); } }
阅读全文
0 0
- Spring Transaction#TransactionalEventListener
- spring Transaction
- spring Transaction
- SPRING TRANSACTION
- spring transaction
- Spring Transaction
- spring transaction
- spring Transaction
- spring- transaction
- Spring transaction
- Spring Transaction
- Spring transaction处理技术
- Spring's transaction configuration
- Spring transaction configuration
- spring transaction setting
- Xml Spring iBatis transaction
- Spring --- Transaction Management
- spring hibernate transaction
- 素数笔记
- java连接带有密码的https的例子
- 详解用Spring Boot零配置快速创建web项目
- NOIP2017模拟赛 好线路(dp)
- Spring+SpringMVC+MyBatis+easyUI整合基础篇(八)mysql中文查询bug修复
- Spring Transaction#TransactionalEventListener
- 粒子群算法形象解释
- PHPWeb开发相关知识学习记录
- spring boot 集成mybatis
- 哪些情况是友情链接作弊?总结了11种方法!
- python导入词云包失败:ImportError:cannot import name ‘WordCloud’的解决办法
- 2017-11-1 & 2017-11-2 集训总结
- 【洛谷 2898】 [USACO08JAN]haybale猜测Haybale Guessing
- 11.2第二节课