Seata1.3整合nacos1.3.2遇到的坑

    科技2024-12-03  16

    Seata1.3整合nacos1.3.2遇到的坑

    启动报错

    Caused by: java.lang.ClassNotFoundException: io.seata.spring.annotation.dataCaused by: java.lang.ClassNotFoundException: io.seata.spring.annotation.datasource.SeataAutoDataSourceProxyCreator

    问题原因seata-all版本不对

    官网推荐pom文件

    <dependency> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> <version>1.3.0(最新)</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> <version>2.2.1.RELEASE</version> <exclusions> <exclusion> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> </exclusion> </exclusions> </dependency>

    但是由于seata-spring-boot-starter所包含的seata-all并不是对应最新的1.3版本,导致ClassNotFoundException

    解决方案:

    修改pom文件

    <dependency> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> <version>1.3.0</version> <exclusions> <exclusion> <groupId>io.seata</groupId> <artifactId>seata-all</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.seata</groupId> <artifactId>seata-all</artifactId> <version>1.3.0</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> <version>2.2.1.RELEASE</version> <exclusions> <exclusion> <groupId>io.seata</groupId> <artifactId>seata-spring-boot-starter</artifactId> </exclusion> </exclusions> </dependency>

    排除掉seata-spring-boot-starter依赖的旧版本seata-all,自己重新添加需要的seata-all版本

    2:seata启动报错

    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

    检查配置文件中store.db数据库相关设置的正确性,数据库地址、用户名、密码均无误

    service.vgroupMapping.my_test_tx_group=default store.mode=db store.db.datasource=druid store.db.dbType=mysql store.db.driverClassName=com.mysql.jdbc.Driver store.db.url=jdbc:mysql://192.168.183.128:3306/seata_order?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true store.db.user=root store.db.password=123456 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.db.driverClassName=com.mysql.jdbc.Driver

    将其修改为com.mysql.cj.jdbc.Driver即可正常启动

    Processed: 0.009, SQL: 8