Spring事务代码,

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

WebApplicationContext contextLoader = ContextLoader.getCurrentWebApplicationContext();//springboot项目这个获取可能会是null
        DataSourceTransactionManager transactionManager = contextLoader.getBean("transactionManager", DataSourceTransactionManager.class);
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
           for(String errCode:serviceList) {
              tBChnlMerPoolBasicService.changePool(errCode+"_"+cmp_next_old, errCode+"_"+cmp_next_new);
           }
//         Integer.parseInt(newCode);
        } catch (Exception e) {
            e.printStackTrace();
            transactionManager.rollback(status);
            sendErr("商户池切换失败", response);
            return;
        } 
        transactionManager.commit(status);

事务管理,事务定义,事务状态,

转载于:https://my.oschina.net/Skynet01/blog/3001015

你可能感兴趣的:(Spring事务代码,)