seata集成nacos
#nacos集成nacos并配置mysql数据源
1. 所需依赖
<!--seata 分布式事务--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> </dependency>
2. 打开seata目录,找到sql文件
3. 打开配置文件配置数据源我们需要修改的是application.yml文件,另一个带example的是官方提供的模板文件
4. 我们打开,然后将以下信息进行添加,可复制后进行修改这里面的配置需要相互对应的修改,不能乱改
# Copyright 1999-2019 Seata.io Group. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. server: port: 7091 spring: application: name: seata-server logging: config: classpath:logback-spring.xml file: path: ${user.home}/logs/seata extend: logstash-appender: destination: 127.0.0.1:4560 kafka-appender: bootstrap-servers: 127.0.0.1:9092 topic: logback_to_logstash console: user: username: seata password: seata seata: config: # support: nacos, consul, apollo, zk, etcd3 type: nacos nacos: server-addr: 127.0.0.1:8848 namespace: train group: SEATA_GROUP username: password: context-path: data-id: seataServer.properties registry: # support: nacos, eureka, redis, zk, consul, etcd3, sofa #type: file type: nacos nacos: application: seata-server server-addr: 127.0.0.1:8848 group: SEATA_GROUP namespace: train cluster: default username: password: store: # support: file 、 db 、 redis mode: file # server: # service-port: 8091 #If not configured, the default is '${server.port} + 1000' security: secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017 tokenValidityInMilliseconds: 1800000 ignore: urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/api/v1/auth/login
5. 打开nacos配置中心,将上面配置的文件加入到配置中心
store.db.datasource=druid store.db.dbType=mysql store.db.driverClassName=com.mysql.cj.jdbc.Driver store.db.url=jdbc:mysql://localhost:3306/seata?useUnicode=true&rewriteBatchedStatements=true store.db.user=root store.db.password=root 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 # 和微服务模块的seata.tx-service-group保持一致 service.vgroupMapping.train-group=default service.default.grouplist=127.0.0.1:8091
6. 配置idea中的模块配置文件
将以下配置添加到配置中,注意,配置文件和上面的相互对应,如果需要修改的话,请将其他的配置文件全部修改
seata: # seata配置 tx-service-group: train-group # 事务组 service: # seata服务 vgroup-mapping: # 事务组映射 train-group: default # 事务组名称,需要和tx-service-group一致 grouplist: # 注册中心 default: 127.0.0.1:8091 #seata服务地址 registry: # 注册中心 type: nacos # 注册中心类型 nacos: application: seata-server # seata服务名称 server-addr: 127.0.0.1:8848 # 注册中心地址 group: SEATA_GROUP # 注册中心组 namespace: train # 注册中心命名空间 username: password: config: type: nacos nacos: server-addr: 127.0.0.1:8848 group: SEATA_GROUP namespace: train dataId: seataServer.properties username: password: