(1) 添加jar


         
            com.codingapi
            transaction-springcloud
            ${lcn.last.version}
            
                
                    org.slf4j
                    *
                
            
        

        
            com.codingapi
            tx-plugins-db
            ${lcn.last.version}
            
                
                    org.slf4j
                    *
                
            
        

(2)修改配置文件application.properties
关键点2:

tm.manager.url=http://127.0.0.1:7000/tx/manager/

(3) 添加文件TxManagerTxUrlServiceImpl(关键3)


package com.jh.service.impl;

import com.codingapi.tx.config.service.TxManagerTxUrlService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 *  //关键点3:
 */
@Service
public class TxManagerTxUrlServiceImpl implements TxManagerTxUrlService{
    @Value("${tm.manager.url}")
    private String url;
    @Override
    public String getTxUrl() {
        System.out.println("load tm.manager.url ");
        return url;
    }
}

(4)服务层函数上加上@Transactional和@TxTransaction/(关键4)


  @TxTransaction//关键点,非常关键,否则没效果
@Transactional
    public int saveTheme(String tName, String tDescription, Integer blockId) {
            int rs1 = themeDao.saveTheme(tName, tDescription, blockId);// 保存1
        return rs1;

    }