nacos1.3 + seata1.4
导入依赖
<!-- seata 相关依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<exclusions>
<!--排除依赖 指定版本-->
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
</exclusion>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.4.0</version>
</dependency>
配置文件
# 分布式事务配置
seata:
tx-service-group: my_test_tx_group
enable-auto-data-source-proxy: true
registry:
type: nacos
nacos:
server-addr: 192.168.1.63:8848
namespace: 5b83b812-0617-497f-b12a-94d0d38e3304
group: SEATA_GROUP
config:
type: nacos
nacos:
server-addr: 192.168.1.63:8848
namespace: 5b83b812-0617-497f-b12a-94d0d38e3304
group: SEATA_GROUP
开启注解
@GlobalTransactional
public void placeOrder(String userId, String commodityCode, Integer count) {
BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5));
Order order = new Order()
.setUserId(userId)
.setCommodityCode(commodityCode)
.setCount(count)
.setMoney(orderMoney);
orderMapper.insertSelective(order);
storageFeignApi.deduct(commodityCode, count);
}