apache / incubator-seata

:fire: Seata is an easy-to-use, high-performance, open source distributed transaction solution.
https://seata.apache.org/
Apache License 2.0
25.23k stars 8.76k forks source link

seata不兼容openfeign? #2321

Closed ChesterZheng closed 4 years ago

ChesterZheng commented 4 years ago

我的环境是 JDK1.8 SpringBoot-2.1.8.RELEASE SpringCloud-Greenwich.SR2 seata-server-1.1 客户端使用的是spring-cloud-alibaba-seata,排除了seata-spring-boot-starter和seata-all,然后单独引用了seata-spring-boot-starter A模块:web服务,对外接口(引用seata) 以下是启动类注解 @EnableEurekaClient @EnableCircuitBreaker @EnableFeignClients(basePackages = "xxx") @ComponentScan(basePackages = "xxx") @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

B模块:操作mysql的服务(引用seata),同时还使用了自定义注解去动态切换数据源 以下是启动类注解 @EnableEurekaClient @EnableAutoDataSourceProxy @ComponentScan(basePackages = xxx") @MapperScan(basePackages = "xxx") @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)

C模块:redis缓存服务(字典数据) 启动类使用注解同A模块

D模块:公共feign(所有feign调用都在这里),其中C模块的fallback类使用了@Component注解和FallbackFactory并且fallback方法是调用B模块的feign服务

问题:

  1. B模块启动报错,找不到Hikari数据源,但实际我并未使用Hikari,而是使用的Druid
  2. 当我改变@EnableFeignClients的basePackages的时候,报错:No fallback instance of type class
  3. 当我把B模块的feign调用都注释掉,启动类也注释掉@EnableFeignClients,启动成功,seata服务注册到seata-server成功,A模块使用@GlobalTransaction分布式事务成功,其他数据库操作成功 之前的问题我提过issue #2311 当时从demo项目移植到业务系统的时候,就出现第一个错误:Hikari为空,我从pom中排除Hikari,启动可以成功,但是当调用B模块的服务的时候,AbstractRoutingDataSource.determineTargetDataSource()方法第一句断言 Assert.notNull(this.resolvedDataSources, "DataSource router not initialized"); 判断我的数据源并未初始化,但实际模块启动的时候已经初始化过了 实际调用跟断点到determineTargetDataSource()方法的时候 数据源是类似DynamicDataSource$$EnhancerBySpringCGLIB$$7ca89c70$$EnhancerByCGLIB$$ddb00ff这样的对象并且该对象中的resolvedDataSources为空,导致断言我的数据源为空 而摘除了seata相关的依赖跟断点到determineTargetDataSource()方法的时候 就是正常的DruidDataSource
q294881866 commented 4 years ago

跟进中