使用springs TransactionSynchronizationManager时出现问题

发布于 2024-10-22 03:10:34 字数 1240 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

女中豪杰 2024-10-29 03:10:35

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

Don't use Status.STATUS_COMMITTED, it has nothing to do with Spring. Use TransactionSynchronization.STATUS_COMMITTED instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文