使用spring TransactionSynchronizationManager时出现问题

时间:2011-03-16 12:26:10

标签: java spring synchronization jms jmstemplate

我正在使用spring TransactionSynchronizationManager。使用此管理器我注册了一个新的Synchronization TransactionSynchronizationAdapter,并且我覆盖了此TransactionSynchronizationAdapter的afterCompletion(int status)方法。 在此afterCompletion中,status的值必须以提交(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);
          }
        }
      }
    });
       }

1 个答案:

答案 0 :(得分:3)

不要使用Status.STATUS_COMMITTED,它与Spring无关。请改用TransactionSynchronization.STATUS_COMMITTED