1. 下载,解压steata安装包
2. 修改配置里面的端口号
找到自己下载安装包中的conf文件夹下的两个yml文件
将文件中的一些配置端口更改成自己的。
3. 修改配置nacos的文件
// 找到 \script\config-center\nacos文件夹
//打开gitbash执行
./nacos-config.sh
4、数据库中添加对应的表
数据库中的表名称尽量为seata_server,避免后面再去修改配置文件
5、线上nacos配置
在public 下面进行配置,修改自己对应服务器的名称
#Transaction storage configuration, only for the server.
store.mode=db
store.lock.mode=db
store.session.mode=db
#These configurations are required if the `store mode` is `db`.
store.db.datasource=druid
store.db.dbType=mysql
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=jdbc:mysql://127.0.0.1:3306/seata_server?useSSL=false&useUnicode=true&rewriteBatchedStatements=true
store.db.user=root
store.db.password=123456
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.distributedLockTable=distributed_lock
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
6、启动前查看git是否执行完成,完成后会自动消失
双击启动 seata\bin\seata-server.bat
127.0.0.1:7091
登录名称密码都是seata
7、在自己nacos上看是否服务注册成功
查看服务注册列表
8、项目使用依赖
<!-- Seata分布式事务 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-seata</artifactId>
<version>2021.1</version>
</dependency>
<!-- 可能不需要,如果显示有配置类找不到,删掉这个依赖 -->
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.3</version> <!-- 确保这是最新版本 -->
</dependency>
9、项目配置文件
(application-id与你自己服务名称相同,修改自己的nacos地址)
seata:
application-id: health-docter-wallet
enable-auto-data-source-proxy: false
tx-service-group: default_tx_group
registry:
type: nacos
nacos:
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
application: seata-server
cluster: default
config:
type: nacos
nacos:
server-addr: 127.0.0.1:8848
group: SEATA_GROUP
service:
vgroup-mapping:
default_tx_group: default
disable-global-transaction: false
client:
rm:
report-success-enable: true
report-retry-count: 5
10、启动类添加注解
@EnableAutoDataSourceProxy
11、使用接口的初始入口处添加注解
@GlobalTransactional
接下来正常启动项目,然后在你的接口入口整条链路中打上断点,就能在seata可视化页面看到,还可以在idea中控制台的日志打印也能看到
浙公网安备 33010602011771号