使用springs TransactionSynchronizationManager时出现问题
我正在使用 spring TransactionSynchronizationManager。使用此管理器,我注册了一个新的 Synchronization TransactionSynchronizationAdapter ,并重写了此 TransactionSynchronizationAdapter 的 afterCompletion(int status) 方法。 在此 afterCompletion 内,状态值必须为已提交 (0),但它为活动 (0)
这是一段代码::
TransactionSynchronizationManager
.registerSynchronization(new TransactionSynchronizationAdapter() {
public void beforeCompletion(){
int status =Status.STATUS_COMMITTED;
System.out.println("inside before completion block hurray");
}
public void afterCompletion(int status) {
System.out.println("the value of status is " + status);
System.out.println("coming after completion");
if (status == Status.STATUS_COMMITTED) {
final String memcachedKey = getMemcachedKey(pOrderId);
System.out.println("the value of memcached key is inside the aftercompletion " + memcachedKey);
mCmatesMemCachedClient.set(memcachedKey, PROVISIONING_PASS);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Tx commited. Set into memcached:Key="
+ memcachedKey + ",Value=" + PROVISIONING_PASS);
}
}
}
});
}
I am using spring TransactionSynchronizationManager.Using this manager I register a new Synchronization TransactionSynchronizationAdapter and I override the afterCompletion(int status) method of this TransactionSynchronizationAdapter .
Inside this afterCompletion the value of status must be coming as commited(0) but it is coming as active(0)
Here is the piece of code ::
TransactionSynchronizationManager
.registerSynchronization(new TransactionSynchronizationAdapter() {
public void beforeCompletion(){
int status =Status.STATUS_COMMITTED;
System.out.println("inside before completion block hurray");
}
public void afterCompletion(int status) {
System.out.println("the value of status is " + status);
System.out.println("coming after completion");
if (status == Status.STATUS_COMMITTED) {
final String memcachedKey = getMemcachedKey(pOrderId);
System.out.println("the value of memcached key is inside the aftercompletion " + memcachedKey);
mCmatesMemCachedClient.set(memcachedKey, PROVISIONING_PASS);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Tx commited. Set into memcached:Key="
+ memcachedKey + ",Value=" + PROVISIONING_PASS);
}
}
}
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用Status.STATUS_COMMITTED,它与Spring无关。请改用TransactionSynchronization.STATUS_COMMITTED。
Don't use
Status.STATUS_COMMITTED
, it has nothing to do with Spring. UseTransactionSynchronization.STATUS_COMMITTED
instead.