集成seata后启动报错Auto proxy of DataSource can’t be enabled as you’ve created a DataSourceProxy bean

文章讲述了在集成Seata分布式事务框架时遇到的问题,涉及到1.1.0版本后Seata对手动代理的支持变化,以及SpringCloudAlibabastarter版本与Seata版本的不匹配。解决方法包括删除自定义的DataSourceProxy配置,排除内嵌的不匹配版本,并调整到1.4.2版本的依赖和配置。
摘要由CSDN通过智能技术生成

在学习谷粒商城项目的时候,在集成分布式事务框架 seata 遇到一些问题。

集成seata后启动报错:
Caused by: io.seata.common.exception.ShouldNeverHappenException: Auto proxy of DataSource can’t be enabled as you’ve created a DataSourceProxy bean.Please consider removing DataSourceProxy bean or disabling auto proxy of DataSource.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceProxy' defined in class path resource [com/demo/consumer/config/DataSourceProxyConfig.class]: Initialization of bean failed; nested exception is io.seata.common.exception.ShouldNeverHappenException: Auto proxy of DataSource can't be enabled as you've created a DataSourceProxy bean.Please consider removing DataSourceProxy bean or disabling auto proxy of DataSource.
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:879) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at com.demo.consumer.ConsumerDemoApplication.main(ConsumerDemoApplication.java:26) ~[main/:na]
Caused by: io.seata.common.exception.ShouldNeverHappenException: Auto proxy of DataSource can't be enabled as you've created a DataSourceProxy bean.Please consider removing DataSourceProxy bean or disabling auto proxy of DataSource.
	at io.seata.spring.annotation.GlobalTransactionScanner.postProcessBeforeInitialization(GlobalTransactionScanner.java:314) ~[seata-all-1.0.0.jar:1.0.0]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:416) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1788) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	... 15 common frames omitted

参考解决方案来源:https://github.com/apache/incubator-seata/issues/2469

在1.1.0版本升级之后,seata不支持手动代理,所以在我的项目中直接把这个配置文件删掉就行
在这里插入图片描述

其次,因为我引入的是spring-cloud-starter-alibaba-seata的2.2.1.RELEASE依赖

<dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
      <version>2.2.1.RELEASE</version>
</dependency>

它内嵌的是seata-spring-boot-starter 版本 1.2.0。而我安装的seata版本是1.4.2,所以需要排除内嵌的seata-spring-boot-starter版本,重新引入相匹配的seata版本。

参考文章:https://blog.csdn.net/weixin_38582851/article/details/123043582

spring-cloud-alibaba 和 各组件版本的对应关系参考: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>
            <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.4.2</version>
        </dependency>

然后,配置也需要修改。1.4.2版本不需要在项目里引入file.conf和registry.conf了。
application.yaml 配置修改如下:
在这里插入图片描述
然后启动项目测试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值