http://javadaily.cn/articles/2019/12/19/1576731515587.html
在Springcloud Alibaba体系中使用Seata作为分布式事务解决方案,大家可以访问seata官网去了解详情。
这次我们先使用Seata的file配置解决上面出现的问题,后面再来对其改造。
$ sh ./bin/seata-server.sh
bin\seata-server.bat
# Seata 配置项,对应 SeataProperties 类
seata:
enabled: true
application-id: ${spring.application.name}
tx-service-group: ${spring.application.name}-group
enable-auto-data-source-proxy: true
config:
type: nacos
nacos:
namespace:
serverAddr: http://www.smdroadshow.com:8848
group: SEATA_GROUP
userName: "nacos"
password: "nacos"
registry:
type: nacos
nacos:
application: seata-server
server-addr: http://www.smdroadshow.com:8848
namespace:
userName: "nacos"
password: "nacos"
主要修改如下三处:service.vgroup_mapping.
后面的值修改为配置文件spring.cloud.alibaba.seata.tx-service-group
的属性service.default.grouplist=
修改为Seata Server的ip:端口support.spring.datasource.autoproxy
的值修改为true,开启datasource
自动代理
在微服务的业务库下执行如下语句,生成undo_log表
在分布式事务方法入口添加注解@GlobalTransactional
,这里只需要在createOrder
方法上添加此注解即可!
SpringCloud Alibaba微服务实战七 - 分布式事务Seata
原文:https://www.cnblogs.com/ywsheng/p/14972101.html