基于 Seata 1.4.0 版本
首先貼出此項目地址:Seata 分布式事務版本
先了未添加事務項目再看此版本:未添加事務版本
此文章是基于上一篇的項目基礎上添加的內容,所以務必先看上一篇
Seata介紹
解決分布式事務問題,有兩個設計初衷
對業務無侵入:即減少技術架構上的微服務化所帶來的分布式事務問題對業務的侵入
高性能:減少分布式事務解決方案所帶來的性能消耗
seata中有兩種分布式事務實現方案,AT及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 node
default.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 快速開始
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>
分別在除了 seata-eureka, seata-common 模塊的resource目錄下創建 register.cong 和 file.conf 文件,把上面的內容復制進去
修改剛剛加了文件的微服務的 application.yaml 文件,加入如下內容
spring:cloud:alibaba:seata:tx-service-group: my_test_tx_group
使用類DataSourceProxy創建數據源代理。這里DataSourceProxy代理的就是業務數據庫的數據源。所以需要配置代理數據源
@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
);}
}
在創建訂單的方法上面加上 @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
+"') ");log
.info("創建訂單,下單賬戶:[{}] ,商品:[{}],數量:[{}]", userId
, commodityCode
, count
);orderFeignClient
.create(userId
, commodityCode
, count
);log
.info("創建訂單完成!!!");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]
- 數據庫初始化數據
- 測試正常操作流程,下單
- 正常執行操作之后的數據庫
- 正常執行的控制臺輸出
在其他微服務中也可以看到正常提交事務的打印輸出 - 測試異常情況,就在剛剛的基礎上,就先不重新初始化數據了
- 異常操作之后的數據庫
- 異常操作之后的控制臺輸出
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 分布式事务版本的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。