seata1.3.0版本整合nacos踩过的深坑—not support register type: null (SpringBoot、Cloud、CloudAlibaba版本兼容使用)?

问题:在搭建分布式事务seata版本时报错,提示 NotSupportYetException: not support register type: null;从异常提示可以看出应该是版本兼容问题

Exception in thread "main" io.seata.common.exception.NotSupportYetException: not support register type: null
	at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:80)
	at io.seata.config.ConfigurationFactory.getInstance(ConfigurationFactory.java:65)
	at io.seata.server.metrics.MetricsManager.init(MetricsManager.java:49)
	at io.seata.server.Server.main(Server.java:56)
    Caused by: java.lang.IllegalArgumentException: illegal type:null
	at io.seata.config.ConfigType.getType(ConfigType.java:62)
	at io.seata.config.ConfigurationFactory.buildConfiguration(ConfigurationFactory.java:78)

那么检查pom.xml文件,发现版本是SpringCloudAlibaba-2.1.0seata版本是seata-0.9.0,但是此时引入seata-0.9.0版本引入不了@GlobalTransactional注解,所以果断升级seata-1.3.0版本,就可以使用@GlobalTransactional注解,但是在启动时项目时却报出上述异常信息。

注意:为什么果断升级seata-1.3.0
因为官方文档最新显示seata-1.3.0,截图所示:
在这里插入图片描述

 
重新引入seata-1.3.0,如下所示:

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

结果启动项目还是出现如下错误 not support register type: null

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'globalTransactionScanner' defined in class path resource [com/alibaba/cloud/seata/GlobalTransactionAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.spring.annotation.GlobalTransactionScanner]: Factory method 'globalTransactionScanner' threw exception; 
	nested exception is io.seata.common.exception.NotSupportYetException: not support register type: null
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:484) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]

 
最后试了很多个包发现还是依旧是报出这问题,最后看seata官方文档,发现了在seata-0.9.0版本之后用引入jar包的方式变了,需要引入spring-cloud-starter-alibaba-seata即可;这个引入的方式就有点像SpringBoot整合MyBatis,需要引入mybatis-spring-boot-starter,如果是引入mybatis-spring就非常需要注意版本号,一不小心就容易出现版本不兼容或者某个工厂类找不到。

seata官方变更记录就可以看出这个引入jar包的方式前后变化:
在这里插入图片描述

 
使用starter方式重新引入seata包,如下所示:

        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
            <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.3.0</version>
        </dependency>

当引入完这个seata-1.3.0版本之后,依旧还是报出上述问题,最后没得办法还得继续百度搜索,最后发现原来所有答案人家官方文档组件版本说明都已经说的明明白白。各个组件之间需要兼容的什么样的版本号。

▶以后还是尽量先看官网文档,能点都点进去看!

alibaba各组件版本兼容如下所示(第一列和最后一列就是seataalibaba兼容的版本号):
在这里插入图片描述
从上面版本号可以看出,seata-1.3.0版本最少也得使用SpringCloudAlibaba-2.2.3起步,所以将SpringCloudAlibaba升级一个稳定版本,最后试了一下SpringCloudAlibaba-2.2.1版本其实也兼容seata-1.3.0,因为现在SpringCloudAlibaba官网推荐使用版本号是,所以最后决定是用的是SpringCloudAlibaba-2.2.1版本。

一打开SpringCloudAlibaba官方文档显示最新的就是2.2.1RELEASE版本,用这个版本毋庸置疑。
在这里插入图片描述

 
最后也看下SpringBootSpringCloudSpringCloudAlibaba三个的版本使用兼容,如下所示:
在这里插入图片描述
 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个使用Spring Boot和Spring Cloud Alibaba Seata框架实现的TCC模式代码模板: 1. 创建一个Spring Boot项目,添加依赖: ```xml <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-seata</artifactId> <version>2.2.0.RELEASE</version> </dependency> ``` 2. 配置Seata相关信息: ```yaml spring: application: name: tcc-demo seata: enabled: true application-id: ${spring.application.name} tx-service-group: my_tx_group service: vgroup-mapping.my_tx_group: default config: type: nacos nacos: server-addr: localhost:8848 namespace: public registry: type: nacos nacos: server-addr: localhost:8848 namespace: public storage: type: db db: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/seata?useUnicode=true&characterEncoding=utf-8&useSSL=false username: root password: root ``` 3. 创建一个TCC接口: ```java public interface TccService { @TccTransaction(confirmMethod = "confirm", cancelMethod = "cancel") boolean tryMethod(String businessKey, String param); boolean confirm(String businessKey, String param); boolean cancel(String businessKey, String param); } ``` 4. 实现TCC接口: ```java @Service public class TccServiceImpl implements TccService { @Resource private TccMapper tccMapper; @Override public boolean tryMethod(String businessKey, String param) { TccEntity tccEntity = new TccEntity(); tccEntity.setBusinessKey(businessKey); tccEntity.setParam(param); return tccMapper.insert(tccEntity) > 0; } @Override public boolean confirm(String businessKey, String param) { return true; } @Override public boolean cancel(String businessKey, String param) { return tccMapper.deleteByBusinessKey(businessKey) > 0; } } ``` 5. 配置TCC事务管理器: ```java @Configuration public class SeataConfiguration { @Bean public GlobalTransactionScanner globalTransactionScanner() { return new GlobalTransactionScanner("tcc-demo", "my_tx_group"); } @Bean public TccTransactionAspect tccTransactionAspect() { return new TccTransactionAspect(); } @Bean public DataSourceProxy dataSourceProxy(DataSource dataSource) { return new DataSourceProxy(dataSource); } } ``` 6. 测试TCC接口: ```java @RestController @RequestMapping("/tcc") public class TccController { @Resource private TccService tccService; @PostMapping("/try") public boolean tryMethod(@RequestParam String businessKey, @RequestParam String param) { return tccService.tryMethod(businessKey, param); } } ``` 以上是一个简单的TCC模式代码模板,可以根据实际业务需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

魔道不误砍柴功

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值