当前位置: 首页 > news >正文

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:

相关文章:

  • 基数排序【C语言】
  • 一.数据治理理论架构
  • Copilot Next Edit Suggestions(预览版)
  • 2025年-G4--lc79--Best Time to Buy and Sell Stock(java版)
  • 基于机器学习的多浮埋层 LDMOS 建模与击穿电压优化
  • 【复现DeepSeek-R1之Open R1实战】系列4:SFT和GRPO源码逐行深度解析(上)(3万字长文,从零开始到入门,包含详细的拓展基础知识)
  • Leetcode 227-基本计算器 II
  • 【C++指南】类和对象(十):const成员函数
  • Python学习心得raise关键字
  • OpenHarmonry 5.0.1源码下载与编译
  • 【vmware虚拟机安装教程】
  • 【达梦DM】DM在windows下的安装
  • java速通笔记
  • Weboffice在线Word权限控制:限制编辑,只读、修订、禁止复制等
  • ping6 命令介绍和 IPv6 常见的网段划分
  • 论文笔记(七十二)Reward Centering(一)
  • python使用自定义注解类和装饰器来实现函数的额外行为
  • 找工作相关(更新中)
  • 浪漫元素在室内设计中的应用
  • SD NAND 的 SDIO在STM32上的应用详解(上篇)
  • wordpress做电影网站/百度快照推广效果怎样
  • 石排镇仿做网站/网络引流怎么做啊?
  • 网站运营推广该如何做/软件推广平台有哪些?哪个比较好
  • 安徽省政府网站官网/百度关键词排名推广工具
  • 高端建站行业/百度提交入口网址
  • 百度工具网站改版/seo是什么简称