Seata 官网基于 docker 部署:https://seata.io/zh-cn/docs/ops/deploy-by-docker.html
1. 直接在 虚拟机 上执行
docker run --name seata-server \
-p 8091:8091 \
-e SEATA_IP=192.168.0.101 \
-e SEATA_PORT=8091 \
seataio/seata-server
拉取 lastest 镜像并启动容器
其中 192.168.0.101 为虚拟机ip
2. 项目 的pom.xml 里导入 坐标(需要注意 相关组件版本:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E):
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> <version>2.2.5.RELEASE</version> </dependency>
3. SpringBootApplication 启动类上添加 @EnableAutoDataSourceProxy 注解
4. 修改 hailtaxi-driver-dev.yml 配置,添加 seata 相关内容:
# 配置 seata seata: enabled: true application-id: ${spring.application.name} tx-service-group: my_tx_group enable-auto-data-source-proxy: true data-source-proxy-mode: AT use-jdk-proxy: false scan-packages: firstPackage,secondPackage excludes-for-scanning: firstBeanNameForExclude,secondBeanNameForExclude excludes-for-auto-proxying: firstClassNameForExclude,secondClassNameForExclude client: rm: async-commit-buffer-limit: 10000 report-retry-count: 5 table-meta-check-enable: false report-success-enable: false saga-branch-register-enable: false saga-json-parser: fastjson saga-retry-persist-mode-update: false saga-compensate-persist-mode-update: false tcc-action-interceptor-order: -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000 sql-parser-type: druid lock: retry-interval: 10 retry-times: 30 retry-policy-branch-rollback-on-conflict: true tm: commit-retry-count: 5 rollback-retry-count: 5 default-global-transaction-timeout: 60000 degrade-check: false degrade-check-period: 2000 degrade-check-allow-times: 10 interceptor-order: -2147482648 #Ordered.HIGHEST_PRECEDENCE + 1000 undo: data-validation: true log-serialization: jackson log-table: undo_log only-care-update-columns: true compress: enable: true type: zip threshold: 64k load-balance: type: RandomLoadBalance virtual-nodes: 10 service: vgroup-mapping: my_tx_group: default grouplist: default: 192.168.0.101:8091 enable-degrade: false disable-global-transaction: false transport: shutdown: wait: 3 thread-factory: boss-thread-prefix: NettyBoss worker-thread-prefix: NettyServerNIOWorker server-executor-thread-prefix: NettyServerBizHandler share-boss-worker: false client-selector-thread-prefix: NettyClientSelector client-selector-thread-size: 1 client-worker-thread-prefix: NettyClientWorkerThread worker-thread-size: default boss-thread-size: 1 type: TCP server: NIO heartbeat: true serialization: seata compressor: none enable-tm-client-batch-send-request: false enable-rm-client-batch-send-request: true rpc-rm-request-timeout: 30000 rpc-tm-request-timeout: 30000
5. idea 启动项目,报错: endpoint format should like ip:port
可能的原因:估计和加载顺序、spring.application.name 配置被覆盖有关。
解决方案:
将 seata 配置移到 bootstrap.yml 配置文件中即可,即 和 spring.application.name 一起加载