目录
1.下载seata1.7.0.zip
2.上传至云服务器,使用unar工具解压
3.配置application.yml,主要配置如下参数
4.为seata执行mysql脚本
5.配置nacos配置中心
*6.启动seata服务器
问题:“cause:can not register RM,err:can not connect to services-server”
*7.SpringBoot整合Seata
问题:“BeanCreationException: Error creating bean with name 'dataSourceProperties' ”
1.下载seata1.7.0.zip
https://download.csdn.net/download/lmj3732018/88867613?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522172355995516800180652535%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=172355995516800180652535&biz_id=1&utm_medium=distribute.pc_search_result.none-task-download-2~all~first_rank_ecpm_v1~rank_v31_ecpm-7-88867613-null-null.142^v100^pc_search_result_base1&utm_term=seata&spm=1018.2226.3001.4187.8
2.上传至云服务器,使用unar工具解压
3.配置application.yml,主要配置如下参数
seata:
config:
# support: nacos, consul, apollo, zk, etcd3
type: nacos
nacos:
server-addr:
namespace:
group:
username:
password:
data-id:
registry:
# support: nacos, eureka, redis, zk, consul, etcd3, sofa
type: nacos
nacos:
application:
server-addr:
group:
namespace:
cluster:
username:
password:
context-path:
store:
# support: file 、 db 、 redis
mode: db
session:
mode: db
lock:
mode: db
db:
datasource: druid
db-type: mysql
driver-class-name: com.mysql.cj.jdbc.Driver
url:
user:
password:
min-conn: 10
max-conn: 100
global-table: global_table
branch-table: branch_table
lock-table: lock_table
distributed-lock-table: distributed_lock
query-limit: 1000
max-wait: 5000
4.为seata执行mysql脚本
5.配置nacos配置中心
transport.type=TCP
transport.server=NIO
transport.heartbeat=true
transport.enableClientBatchSendRequest=false
transport.threadFactory.bossThreadPrefix=NettyBoss
transport.threadFactory.workerThreadPrefix=NettyServerNIOWorker
transport.threadFactory.serverExecutorThreadPrefix=NettyServerBizHandler
transport.threadFactory.shareBossWorker=false
transport.threadFactory.clientSelectorThreadPrefix=NettyClientSelector
transport.threadFactory.clientSelectorThreadSize=1
transport.threadFactory.clientWorkerThreadPrefix=NettyClientWorkerThread
transport.threadFactory.bossThreadSize=1
transport.threadFactory.workerThreadSize=default
transport.shutdown.wait=3
#my-tx-groip需要记住,后面要用
service.vgroupMapping.my_tx_group=default
service.default.grouplist=0.0.0.0:8091
service.enableDegrade=false
service.disableGlobalTransaction=false
client.rm.asyncCommitBufferLimit=10000
client.rm.lock.retryInterval=10
client.rm.lock.retryTimes=30
client.rm.lock.retryPolicyBranchRollbackOnConflict=true
client.rm.reportRetryCount=5
client.rm.tableMetaCheckEnable=false
client.rm.tableMetaCheckerInterval=60000
client.rm.sqlParserType=druid
client.rm.reportSuccessEnable=false
client.rm.sagaBranchRegisterEnable=false
client.tm.commitRetryCount=5
client.tm.rollbackRetryCount=5
client.tm.defaultGlobalTransactionTimeout=60000
client.tm.degradeCheck=false
client.tm.degradeCheckAllowTimes=10
client.tm.degradeCheckPeriod=2000
store.mode=db
store.publicKey=
store.file.dir=file_store/data
store.file.maxBranchSessionSize=16384
store.file.maxGlobalSessionSize=512
store.file.fileWriteBufferCacheSize=16384
store.file.flushDiskMode=async
store.file.sessionReloadReadSize=100
store.db.datasource=druid
store.db.dbType=mysql
#数据库修改上面配置的位置
store.db.driverClassName=com.mysql.cj.jdbc.Driver
store.db.url=
store.db.user=
store.db.password=
#--------------#
store.db.minConn=5
store.db.maxConn=30
store.db.globalTable=global_table
store.db.branchTable=branch_table
store.db.queryLimit=100
store.db.lockTable=lock_table
store.db.maxWait=5000
store.redis.mode=single
store.redis.single.host=127.0.0.1
store.redis.single.port=6379
store.redis.maxConn=10
store.redis.minConn=1
store.redis.maxTotal=100
store.redis.database=0
store.redis.password=
store.redis.queryLimit=100
server.recovery.committingRetryPeriod=1000
server.recovery.asynCommittingRetryPeriod=1000
server.recovery.rollbackingRetryPeriod=1000
server.recovery.timeoutRetryPeriod=1000
server.maxCommitRetryTimeout=-1
server.maxRollbackRetryTimeout=-1
server.rollbackRetryTimeoutUnlockEnable=false
client.undo.dataValidation=true
client.undo.logSerialization=jackson
client.undo.onlyCareUpdateColumns=true
server.undo.logSaveDays=7
server.undo.logDeletePeriod=86400000
client.undo.logTable=undo_log
client.undo.compress.enable=true
client.undo.compress.type=zip
client.undo.compress.threshold=64k
log.exceptionRate=100
transport.serialization=seata
transport.compressor=none
metrics.enabled=false
metrics.registryType=compact
metrics.exporterList=prometheus
metrics.exporterPrometheusPort=9898
*6.启动seata服务器
../bin/seata-server.sh -h <真实ip>
问题:“cause:can not register RM,err:can not connect to services-server”
这个问题是因为在nacos里注册的网段是内网,而外部服务无法访问
*7.SpringBoot整合Seata
依赖项:
<!--seata所需-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-seata</artifactId>
<version>2.2.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-spring-boot-starter</artifactId>
<version>1.7.0-native-rc2</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
配置 yml:
seata:
enabled: true
#Seata 事务组编号,用于TC集群
#要和 service.vgroupMapping.my_tx_group=default 中配置的相同
tx-service-group: my_tx_group
service:
vgroup-mapping:
my_tx_group: default
## 关闭自动代理
enable-auto-data-source-proxy: false
config: #配置中心,从nacos获取配置
type: nacos
nacos:
server-addr: #nacos地址
group: SEATA_GROUP
data-id: seataServer.properties
username:
password:
registry: #TC服务注册中心的配置,微服务根据这些信息去注册中心获取tc服务地址
type: nacos #注册中心类型 nacos
nacos:
application: seata-server #seata服务名称
server-addr: #nacos地址
group: SEATA_GROUP #seata组,与seata所在组保持一致
username:
password:
application-id: ${spring.application.name}
配置数据源代理:
@Configuration
public class DataSourceConfig {
@Bean
@Primary
public DataSource dataSource(DataSourceProperties properties) {
DataSource dataSource = properties.initializeDataSourceBuilder().build();
return new DataSourceProxy(dataSource);
}
}
问题:“BeanCreationException: Error creating bean with name 'dataSourceProperties' ”
这个错误信息表明在创建 dataSourceProperties
Bean 时遇到了问题,确保 DataSourceConfig
类正确配置了 DataSourceProperties
Bean,以及pom中包含了必要的依赖,特别是数据库驱动和 Spring Data 相关的依赖