作者:小叶2502854061 | 来源:互联网 | 2023-06-07 10:11
注意事项:1.tx-lcn版本5.0.2.RELEASE,对应springboot版本:2.1.2.RELEASE2.先启动LCN事务协调器,具体见:【配置LCN事物协调器】3.客
注意事项:
1.tx-lcn版本5.0.2.RELEASE,对应springboot版本:2.1.2.RELEASE
2.先启动LCN事务协调器,具体见:【配置LCN事物协调器】
3.客户端添加依赖:
com.codingapi.txlcn
txlcn-tc
5.0.2.RELEASE
com.codingapi.txlcn
txlcn-txmsg-netty
5.0.2.RELEASE
4.配置事务管理器协调地址
tx-lcn:
client:
manager-address: 127.0.0.1:8070
5.添加分布式事务管理器的注解
@SpringBootApplication
@RestController
@EnableDistributedTransaction
public class Service1Application{
....
}
6.要进行的所有一串调用的分布式事物都加注解,如果是对数据库操作的话,还需要添加spring事物支持
@Transactional
@LcnTransaction
public void saveUser(String userName) {...}
7.具体代码demo:代码demo
8.查看UI及测试
9.http://localhost/save?goodsName=apple&userName=李四。第三次的时候事物回滚成功