首页 > 其他分享 >springboot3(cloud 2022.0.0)整合seata1.7.1

springboot3(cloud 2022.0.0)整合seata1.7.1

时间:2024-07-02 09:55:43浏览次数:1  
标签:seata License seata1.7 nacos server springboot3 NULL 2022.0 log

一、第一步下载对应版本的seata服务

 

 

二、修改conf下的application.yml配置

注意:主要是连接nacos的一些配置:注册中心和服务发现的配置

 1 #  Copyright 1999-2019 Seata.io Group.
 2 #
 3 #  Licensed under the Apache License, Version 2.0 (the "License");
 4 #  you may not use this file except in compliance with the License.
 5 #  You may obtain a copy of the License at
 6 #
 7 #  http://www.apache.org/licenses/LICENSE-2.0
 8 #
 9 #  Unless required by applicable law or agreed to in writing, software
10 #  distributed under the License is distributed on an "AS IS" BASIS,
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #  See the License for the specific language governing permissions and
13 #  limitations under the License.
14 
15 server:
16   port: 7091
17  
18 spring:
19   application:
20     name: seata-server
21  
22 logging:
23   config: classpath:logback-spring.xml
24   file:
25     path: D:\seatalog\seata-server-1.7.0\seata\logs.
26   extend:
27     logstash-appender:
28       destination: 127.0.0.1:4560
29     kafka-appender:
30       bootstrap-servers: 127.0.0.1:9092
31       topic: logback_to_logstash
32  
33 console:
34   user:
35     username: seata
36     password: seata
37 seata:
38   config:
39     # support: nacos, consul, apollo, zk, etcd3
40     type: nacos # 指定配置中心为nacos
41     nacos:
42       server-addr: 127.0.0.1:8848  # nacos的ip端口
43       group: DEFAULT_GROUP    # 对应的组,默认为DEFAULT_GROUP
44       namespace: e984372a-17f3-44fc-aa0e-7b3c384fe94c # 对应的命名空间,在nacos中配置
45       data-id: seataServer.properties # nacos中存放seata的配置文件,后面会提该文件的使用方式,相当于seata服务启动的时候需要注册到nacos,并使用nacos中的配置文件
46   registry:
47     # support: nacos, eureka, redis, zk, consul, etcd3, sofa
48     type: nacos
49     nacos:
50       application: seata-server
51       server-addr: 127.0.0.1:8848
52       group: DEFAULT_GROUP
53       namespace:
54       cluster: default
55       username:
56       password:
57       context-path:
58   store:
59     # support: file 、 db 、 redis
60     mode: file
61 #  server:
62 #    service-port: 8091 #If not configured, the default is '${server.port} + 1000'
63   security:
64     secretKey: SeataSecretKey0c382ef121d778043159209298fd40bf3850a017
65     tokenValidityInMilliseconds: 1800000
66     ignore:
67       urls: /,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.jpeg,/**/*.ico,/api/v1/auth/login

  2.1配置好之后创建seata服务连接数据库,库中插入表。在 \seata\script\server\db 下有sql文件

  2.2在需要用到seata的业务数据库下创建undo_log表

 1 drop table `undo_log`;
 2 CREATE TABLE `undo_log` (
 3   `id` bigint(20) NOT NULL AUTO_INCREMENT,
 4   `branch_id` bigint(20) NOT NULL,
 5   `xid` varchar(100) NOT NULL,
 6   `context` varchar(128) NOT NULL,
 7   `rollback_info` longblob NOT NULL,
 8   `log_status` int(11) NOT NULL,
 9   `log_created` datetime NOT NULL,
10   `log_modified` datetime NOT NULL,
11   `ext` varchar(100) DEFAULT NULL,
12   PRIMARY KEY (`id`),
13   UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
14 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

  2.3:访问nacos看一下seata服务有没有被naocs发现
  2.4:为seata创建命名空间,名字要与data-id一致

配置文件在 \seata\script\config-center下有个config.txt复制到naocs配置文件中  主要要修改自己的数据库地址,绑定seata表

 

三、双击启动bin目录下脚本,seata-server.bat
 浏览器访问:http://127.0.0.1:7091 可视化界面

四、整合到项目中导入的依赖:

  <!--分布式事务seata-->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
        </dependency>

 

在yaml文件中的配置:

 1 seata:
 2   tx-service-group: gulimall-ware # 事务分组名称,要和服务端对应
 3   service:
 4     vgroup-mapping:
 5       gulimall-ware: default # key是事务分组名称 value要和服务端的机房名称保持一致
 6   registry:  # 业务服务每一个都需要配置需要在naocs发现seata服务
 7     type: nacos
 8     nacos:
 9       server-addr: 127.0.0.1:8848
10       namespace: public
11       group: DEFAULT_GROUP
12       application: seata-server

 

启动项目测试
使用方法:在业务总事物方法上加上  @GlobalTransactional

如果回滚失效,基本上是没有获取到XID,查看XID方法: RootContext.getXID()
解决方法:不要导错依赖,使用:spring-cloud-starter-alibaba-seata
     或者重写  RequestInterceptor的apply方法 把XID传递到远程服务请求头中。feign底层会丢失所有请求头,创建新客户端进行http调用,所以会有XID为null的问题。

 

标签:seata,License,seata1.7,nacos,server,springboot3,NULL,2022.0,log
From: https://www.cnblogs.com/Zz198/p/18279317

相关文章

  • SpringBoot3项目打war包部署至Tomcat
    前言:近期,在搞国产中间件的部署,那么则需要将项目打为war包,并且在tomcat内尝试成了再去部署到国产中间件吧,以免引起不必要的时间浪费。1、准备工作准备好tomcat10的版本准备好SpringBoot项目2、代码改造打war包需要从springboot依赖中排除tomcat相关的包,我们以Snowy国产快速......
  • SpringBoot3整合SpringDoc实现在线接口文档
    写在前面在现目前项目开发中,一般都是前后端分离项目。前端小姐姐负责开发前端,苦逼的我们负责后端开发事实是一个人全干,在这过程中编写接口文档就显得尤为重要了。然而作为一个程序员,最怕的莫过于自己写文档和别人不写文档大家都不想写文档,那这活就交给今天的主角Swagger来实现......
  • springboot3项目的搭建四.3(security登录认证配置)
    security的jwt验证:总体来说,我们加入依赖项,security就已经开始生效了,但是使用的默认的UserDetails和UserDetailsService,一、我们只要继承UserDetailsService,在数据库中查询用户和权限列表,封装成UserDetails的实现类,返回就可以实现,security验证的接管,最多在security配置类中,放行......
  • SpringBoot3.0.x适配mybatis版本
    SpringBoot适配mybatis版本最低为3.0.3<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version><......
  • SpringBoot3集成Knife4j生成接口文档
    导入依赖<dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId><version>4.4.0</version></dependency>注意:SpringBoot......
  • Sz-Admin | SpringBoot3 JDK21 Vue3开源后台RBAC管理系统 | 2024年好用的开源RBAC管理
    简介接触了很多优秀的开源和闭源项目,在使用过程中也发现一些问题,不甘满足的我遂产生了想法:于是利用休息时间编写了一套后台管理系统,它灵活、简洁、高效,拥抱最新的技术,因此Sz-Admin便诞生了,也意为升职Admin,升职加薪节节高。SzAdmin,一个基于SpringBoot3、Vue3和El......
  • springboot3整合高版本spring data neo4j
    本博客适用于springboodataneo4j7.2.6版本,详情阅读官网https://docs.spring.io/spring-data/neo4j/reference/7.2/introduction-and-preface/index.html,中文网只更新到了6版本entity->nodeentity->relation@Node("Movie")//取代了老版本的nodeentity,他表示的就是labelp......
  • Springboot3.x 实现考试系统中接打电话的识别与处理
    使用Springboot3.x实现考试系统中接打电话的识别与处理在考试过程中,考生接打电话可能会导致考试舞弊或注意力分散,这对考试的公正性和有效性构成了威胁。因此,如何在考试系统中识别并处理考生接打电话的行为,成为一个重要的技术课题。技术实现为了解决这一问题,我们可以使用Sp......
  • springboot3项目的搭建四.1(security登录认证配置)
    SpringBoot3整合SpringSecurityMaven<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.2.2</version><relativeP......
  • springboot3项目的搭建四.2(security登录认证配置)
    SpringBoot3+SpringSecurity整合Security导包:<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId></dependency>模拟Redis存储登录信息:publicclassCacheEntityimpl......