基于 Seata 1.4.0 版本
首先贴出此项目地址:Seata 分布式事务版本
先了未添加事务项目再看此版本:未添加事务版本

此文章是基于上一篇的项目基础上添加的内容,所以务必先看上一篇

Seata介绍

解决分布式事务问题,有两个设计初衷

对业务无侵入:即减少技术架构上的微服务化所带来的分布式事务问题对业务的侵入
高性能:减少分布式事务解决方案所带来的性能消耗

seata中有两种分布式事务实现方案,AT及TCC

  • AT模式主要关注多 DB 访问的数据一致性,当然也包括多服务下的多 DB 数据访问一致性问题

  • TCC 模式主要关注业务拆分,在按照业务横向扩展资源时,解决微服务间调用的一致性问题

AT模式

Seata AT模式是基于XA事务演进而来的一个分布式事务中间件,XA是一个基于数据库实现的分布式事务协议,本质上和两阶段提交一样,需要数据库支持,Mysql5.6以上版本支持XA协议,其他数据库如Oracle,DB2也实现了XA接口

TCC模式

seata也针对TCC做了适配兼容,支持TCC事务方案,原理前面已经介绍过,基本思路就是使用侵入业务上的补偿及事务管理器的协调来达到全局事务的一起提交及回滚。

接下来一步一步往上一篇博客的项目加 Seata 内容,达到 Seata 分布式事务的效果

首先介绍下,此次 seata 分布式事务的模式设置为 file,所以先介绍一下 register.conf 和 file.conf 文件

1、register.conf

registry {# file 、nacos 、eureka、redis、zk、consul、etcd3、sofatype = "file" # 这里设置 seata 的模式,这里设置为 filenacos {serverAddr = "localhost:8848"namespace = ""cluster = "default"}eureka {serviceUrl = "http://localhost:8761/eureka"application = "default"weight = "1"}redis {serverAddr = "localhost:6379"db = "0"}zk {cluster = "default"serverAddr = "127.0.0.1:2181"session.timeout = 6000connect.timeout = 2000}consul {cluster = "default"serverAddr = "127.0.0.1:8500"}etcd3 {cluster = "default"serverAddr = "http://localhost:2379"}sofa {serverAddr = "127.0.0.1:9603"application = "default"region = "DEFAULT_ZONE"datacenter = "DefaultDataCenter"cluster = "default"group = "SEATA_GROUP"addressWaitTime = "3000"}file {name = "file.conf"}
}config {# file、nacos 、apollo、zk、consul、etcd3type = "file"nacos {serverAddr = "localhost"namespace = ""}consul {serverAddr = "127.0.0.1:8500"}apollo {app.id = "seata-server"apollo.meta = "http://192.168.1.204:8801"}zk {serverAddr = "127.0.0.1:2181"session.timeout = 6000connect.timeout = 2000}etcd3 {serverAddr = "http://localhost:2379"}file {name = "file.conf"}
}

2、file.conf

transport {# tcp udt unix-domain-sockettype = "TCP"#NIO NATIVEserver = "NIO"#enable heartbeatheartbeat = true#thread factory for nettythread-factory {boss-thread-prefix = "NettyBoss"worker-thread-prefix = "NettyServerNIOWorker"server-executor-thread-prefix = "NettyServerBizHandler"share-boss-worker = falseclient-selector-thread-prefix = "NettyClientSelector"client-selector-thread-size = 1client-worker-thread-prefix = "NettyClientWorkerThread"# netty boss thread size,will not be used for UDTboss-thread-size = 1#auto default pin or 8worker-thread-size = 8}shutdown {# when destroy server, wait secondswait = 3}serialization = "seata"compressor = "none"
}
service {#vgroup->rgroup# 这里主要需要注意的地方,my_test_tx_group 名称必须和 spring.cloud.alibaba.seata.tx-service-group 配置的值一样vgroup_mapping.my_test_tx_group = "default"#only support single nodedefault.grouplist = "127.0.0.1:8091"#degrade current not supportenableDegrade = false#disabledisable = false#unit ms,s,m,h,d represents milliseconds, seconds, minutes, hours, days, default permanentmax.commit.retry.timeout = "-1"max.rollback.retry.timeout = "-1"
}client {async.commit.buffer.limit = 10000lock {retry.internal = 10retry.times = 30}report.retry.count = 5tm.commit.retry.count = 1tm.rollback.retry.count = 1
}## transaction log store
store {## store mode: file、dbmode = "db"## file storefile {dir = "sessionStore"# branch session size , if exceeded first try compress lockkey, still exceeded throws exceptionsmax-branch-session-size = 16384# globe session size , if exceeded throws exceptionsmax-global-session-size = 512# file buffer size , if exceeded allocate new bufferfile-write-buffer-cache-size = 16384# when recover batch read sizesession.reload.read_size = 100# async, syncflush-disk-mode = async}## database storedb {## the implement of javax.sql.DataSource, such as DruidDataSource(druid)/BasicDataSource(dbcp) etc.datasource = "dbcp"## mysql/oracle/h2/oceanbase etc.db-type = "mysql"driver-class-name = "com.mysql.jdbc.Driver"url = "jdbc:mysql://127.0.0.1:3306/seata"user = "root"password = "root"min-conn = 1max-conn = 3global.table = "global_table"branch.table = "branch_table"lock-table = "lock_table"query-limit = 100}
}
lock {## the lock store mode: local、remotemode = "remote"local {## store locks in user's database}remote {## store locks in the seata's server}
}
recovery {#schedule committing retry period in millisecondscommitting-retry-period = 1000#schedule asyn committing retry period in millisecondsasyn-committing-retry-period = 1000#schedule rollbacking retry period in millisecondsrollbacking-retry-period = 1000#schedule timeout retry period in millisecondstimeout-retry-period = 1000
}transaction {undo.data.validation = trueundo.log.serialization = "jackson"undo.log.save.days = 7#schedule delete expired undo_log in millisecondsundo.log.delete.period = 86400000undo.log.table = "undo_log"
}## metrics settings
metrics {enabled = falseregistry-type = "compact"# multi exporters use comma dividedexporter-list = "prometheus"exporter-prometheus-port = 9898
}support {## springspring {# auto proxy the DataSource beandatasource.autoproxy = false}
}

这里说明下:在使用 Seata 之前,需要先启动 Seata-server 服务,默认的端口:8091(如下图)
seata-server 下载地址:下载Seata-Server [自行选择版本]
详情看文档:Seata 快速开始

  1. seata-common 模块的POM文件注解放开,加上 Seata
<dependencies><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-seata</artifactId><version>2.1.0.RELEASE</version></dependency>
</dependencies>
  1. 分别在除了 seata-eureka, seata-common 模块的resource目录下创建 register.cong 和 file.conf 文件,把上面的内容复制进去
  2. 修改刚刚加了文件的微服务的 application.yaml 文件,加入如下内容
spring:cloud:alibaba:seata:# 注意,值需要和 file.conf 文件配置的组名一致tx-service-group: my_test_tx_group
  1. 使用类DataSourceProxy创建数据源代理。这里DataSourceProxy代理的就是业务数据库的数据源。所以需要配置代理数据源
/*** @author: qiukangming* @date: 2021/01/07 20:25* @version: 1.0* @description: 代理数据源配置类,在每一个需要分布式事务的微服务中配置一份*/@Configuration
public class CustomDataSourceProxyConfig {@Bean@ConfigurationProperties(prefix = "spring.datasource")public DruidDataSource druidDataSource() {return new DruidDataSource();}@Primary@Beanpublic DataSourceProxy dataSource(DruidDataSource druidDataSource) {return new DataSourceProxy(druidDataSource);}
}
  1. 在创建订单的方法上面加上 @GlobalTransactional(name = “order-create”, rollbackFor = Exception.class) 注解,设置分布式事务
@GlobalTransactional(name = "order-create", rollbackFor = Exception.class) //分布式事务的全局事务的入口 ()
public void purchase(String userId, String commodityCode, int count, boolean exception) {//添加日志Date date = new Date();SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String format = simpleDateFormat.format(date);jdbcTemplate.update("insert into log_info(content,createtime) values('测试','"+format+"') ");//调用feign      下单--->扣款log.info("创建订单,下单账户:[{}] ,商品:[{}],数量:[{}]", userId, commodityCode, count);orderFeignClient.create(userId, commodityCode, count);log.info("创建订单完成!!!");//调用feign      扣减库存log.info("开始递减 {} 库存,数量:{}", commodityCode, count);storageFeignClient.deduct(commodityCode, count);log.info("递减 {} 库存成功!!!", commodityCode);//扣减余额log.info("开始扣除 {} 账户 {} 元!", userId, count * 100);userFeignClient.reduce(userId, count * 100, exception);log.info("扣款成功!!!");
}

到此添加的配置就算加完了,现在启动微服务测试

  • 一般启动微服务会打印如下信息就说明配置没有问题
2021-01-08 22:11:05.529  INFO 8564 --- [           main] io.seata.core.rpc.netty.RmRpcClient      : register to RM resourceId:jdbc:mysql://localhost:3306/seata_order
2021-01-08 22:11:05.534  INFO 8564 --- [           main] i.s.c.r.netty.NettyClientChannelManager  : will connect to 127.0.0.1:8091
2021-01-08 22:11:05.534  INFO 8564 --- [           main] io.seata.core.rpc.netty.RmRpcClient      : RM will register :jdbc:mysql://localhost:3306/seata_order
2021-01-08 22:11:05.541  INFO 8564 --- [           main] i.s.core.rpc.netty.NettyPoolableFactory  : NettyPool create channel to transactionRole:RMROLE,address:127.0.0.1:8091,msg:< RegisterRMRequest{resourceIds='jdbc:mysql://localhost:3306/seata_order', applicationId='seata-order', transactionServiceGroup='my_test_tx_group'} >
2021-01-08 22:11:06.569  INFO 8564 --- [lector_RMROLE_1] i.s.common.loader.EnhancedServiceLoader  : load Codec[SEATA] extension by class[io.seata.codec.seata.SeataCodec]
2021-01-08 22:11:06.705  INFO 8564 --- [           main] io.seata.core.rpc.netty.RmRpcClient      : register RM success. server version:1.4.0,channel:[id: 0x865848e9, L:/127.0.0.1:51262 - R:/127.0.0.1:8091]
2021-01-08 22:11:06.705  INFO 8564 --- [           main] i.s.core.rpc.netty.NettyPoolableFactory  : register success, cost 177 ms, version:1.4.0,role:RMROLE,channel:[id: 0x865848e9, L:/127.0.0.1:51262 - R:/127.0.0.1:8091]
  • 数据库初始化数据
  • 测试正常操作流程,下单
  • 正常执行操作之后的数据库
  • 正常执行的控制台输出

    在其他微服务中也可以看到正常提交事务的打印输出
  • 测试异常情况,就在刚刚的基础上,就先不重新初始化数据了
  • 异常操作之后的数据库
  • 异常操作之后的控制台输出
// 用户微服务报错:算术错误 除以 0
java.lang.ArithmeticException: / by zero


在其他微服务中也可以看到事务回滚的日志打印

以上就是 Seata file模式的分布式事务的介绍

说难也不难,主要是配置文件需要配置正确
列举下常见的问题,坑…
  • 配置文件配置的seata组名和file.conf配置的不一致
  • 启动时报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userApplication': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in com.seata.UserApplication: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceProxy' defined in com.seata.UserApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.rm.datasource.DataSourceProxy]: Circular reference involving containing bean 'userApplication' - consider declaring the factory method as static for independence from its containing instance. Factory method 'dataSourceProxy' threw exception; nested exception is java.lang.ExceptionInInitializerErrorat org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:324) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]at com.seata.UserApplication.main(UserApplication.java:38) [classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jdbcTemplate' defined in com.seata.UserApplication: Unsatisfied dependency expressed through method 'jdbcTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceProxy' defined in com.seata.UserApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.rm.datasource.DataSourceProxy]: Circular reference involving containing bean 'userApplication' - consider declaring the factory method as static for independence from its containing instance. Factory method 'dataSourceProxy' threw exception; nested exception is java.lang.ExceptionInInitializerErrorat org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeanByName(AbstractAutowireCapableBeanFactory.java:452) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:526) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:636) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:180) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]... 17 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceProxy' defined in com.seata.UserApplication: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.rm.datasource.DataSourceProxy]: Circular reference involving containing bean 'userApplication' - consider declaring the factory method as static for independence from its containing instance. Factory method 'dataSourceProxy' threw exception; nested exception is java.lang.ExceptionInInitializerErrorat org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1247) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]... 33 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.rm.datasource.DataSourceProxy]: Circular reference involving containing bean 'userApplication' - consider declaring the factory method as static for independence from its containing instance. Factory method 'dataSourceProxy' threw exception; nested exception is java.lang.ExceptionInInitializerErrorat org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]... 47 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: nullat com.seata.UserApplication.dataSourceProxy(UserApplication.java:56) [classes/:na]at com.seata.UserApplication$$EnhancerBySpringCGLIB$$c53bc05b.CGLIB$dataSourceProxy$0(<generated>) ~[classes/:na]at com.seata.UserApplication$$EnhancerBySpringCGLIB$$c53bc05b$$FastClassBySpringCGLIB$$4aa029ae.invoke(<generated>) ~[classes/:na]at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]at com.seata.UserApplication$$EnhancerBySpringCGLIB$$c53bc05b.dataSourceProxy(<generated>) ~[classes/:na]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_212]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_212]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_212]at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_212]at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]... 48 common frames omitted
Caused by: io.seata.common.exception.NotSupportYetException: config type can not be nullat io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:110) ~[seata-all-1.4.1.jar:1.4.1]at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:94) ~[seata-all-1.4.1.jar:1.4.1]at io.seata.rm.datasource.DataSourceProxy.<clinit>(DataSourceProxy.java:62) ~[seata-all-1.4.1.jar:1.4.1]... 59 common frames omitted
这个报错很坑,解决办法是把 target 目录删除,重新编译一下就好了[因为我就是这样,坑了我半天…],整个估计是在resource目录下新加文件的时候没有及时编译过去

SpringCloud分布式事务,版本二:添加 Seata 分布式事务版本相关推荐

  1. 分布式事务(二)LCN分布式事务框架

    1. 简介 LCN框架在2017年6月发布第一个版本,目前最新已经达到5.0版本. LCN早期设计时,1.0版本和2.0版本设计步骤如下: 锁定事务单元(Lock) 确认事务模块状态(Confirm) ...

  2. 分布式事务(三)Seata分布式事务框架-AT模式介绍

    文章目录 Seata介绍 Seata AT事务方案 业务场景 Seata AT基本原理 第一阶段:执行各分支事务 第二阶段:控制全局事务最终提交 第二阶段:控制全局事务最终回滚 Seata AT具体工 ...

  3. Rocksdb的事务(二):完整事务体系的 详细实现

    文章目录 1. 基本事务操作 1.1 TransactionDB -- Pessimistic 1.2 OptimisticTransactionDB 1.3 Read Uncommitted 1.4 ...

  4. 分布式事务(二)、刚性事务之 2PC、3PC

    目录 前言 XA 2PC 3PC 分布式事务: 分布式事务(一).CAP,BASE理论 前言 在前面的文章中我们提到了刚性事务遵循ACID原则,满足强一致性,本篇讲解刚性事务的标准实现2PC(二阶段提 ...

  5. SpringCloud微服务实战——搭建企业级开发框架(二十七):集成多数据源+Seata分布式事务+读写分离+分库分表

      读写分离:为了确保数据库产品的稳定性,很多数据库拥有双机热备功能.也就是,第一台数据库服务器,是对外提供增删改业务的生产服务器:第二台数据库服务器,主要进行读的操作.   目前有多种方式实现读写分 ...

  6. 分布式事务原理及实战seata(转自微信公众号 终码一生 )

    什么是分布式事务? _____________________________________________________________________________ 分布式对应的是单体架构, ...

  7. Seata 分布式事务的使用和原理浅析

    Seata 分布式事务的精简使用教程和原理浅析 一.说明 二.Seata 简介 2.1.Seata 是什么? 2.2.Seata 的整体架构 2.2.1.主要角色 2.2.2.整体架构和工作流程图 2 ...

  8. seata分布式事务解决方案

    下载地址:Releases · seata/seata · GitHub 一.什么是分布式事务 首先这是普通事务: 下面是分布式事务: 在微服务系统中,每个微服务应用都可能会有自己的数据库,它们首先需 ...

  9. 分布式事务(三)、柔性事务之 TCC、Saga、本地消息表、事务消息、最大努力通知

    目录 [前言] TCC Saga [通知型事务] 本地消息表 MQ事务消息 最大努力通知 总结 分布式事务: 分布式事务(一).CAP,BASE理论 分布式事务(二).刚性事务之 2PC.3PC [前 ...

最新文章

  1. C语言中.和->区别
  2. 真正的程序员,从来不会告诉你这些事!
  3. 8种图数据库对 NULL 属性值支持情况
  4. python总结简短_Python简单的基础总结
  5. python获取网页元素坐标_html网页元素在屏幕上的坐标获取
  6. ArcGIS9.3 SDE安装
  7. 企业微信可以批量删除聊天记录吗?
  8. Bitvise SSH Client连接Linux服务器教程和使用
  9. 原生html5时间组件,amazeui时间组件的实现示例
  10. win教程:如何查看本机的IP地址
  11. 手机端,网站页面被浏览器转码
  12. 计算机英语读法语音,英语语音朗读技巧
  13. R语言绘制复杂抽样设计数据cox回归生存曲线(Kaplan-Meier)
  14. 大论文 自动生成标题目录、图目录和表目录
  15. wxpyhton打包后图标背景变黑
  16. 排课系统matlab,matlab数学建模排课
  17. 3021什么意思_3021违章代码罚款金额和含义
  18. 百度地图 marker自定义图标并且删除指定的marker
  19. 我为虎嗅设计APP(一)-逻辑梳理
  20. PPT之如何一键删除所有幻灯片备注?

热门文章

  1. ALV标准过滤功能失效
  2. 涨点小姿势 奥迪TFSI前面数字是什么
  3. ALV_GRID介绍
  4. 长沙经济复苏战打的如何?我们从高桥红星两个市场里找到了答案
  5. 唱《醉赤壁》表白成功!跨越太平洋的爱情没有时差,东八区与西八区同步奔跑
  6. 试说明机器指令和微指令之间的关系_男女关系之间,是他在说谎吗?观察他的肢体语言说明一切...
  7. php并发访问排队_php解决高并发问题
  8. 分类的评估标准_机器学习:模型评估之评估指标
  9. h3c防火墙u200配置命令_网络设备配置——H3C命令行基本操作【分级】
  10. node.js 腾讯镜像站_使用腾讯云提供的针对Nuget包管理器的缓存加速服务