wxrqforever opened a new issue, #7111: URL: https://github.com/apache/incubator-seata/issues/7111
一、问题描述 有个应用同时使用了多个DataSource,应用接入seata后启动报错了,报错日志如下: ``` Description: Parameter 0 of method springFenceConfig in org.apache.seata.spring.boot.autoconfigure.SeataSpringFenceAutoConfiguration required a single bean, but 3 were found: - xxxxDataSource: defined by method 'setDataSource' in class path resource [com/xxxx.class] - xxxx2DataSource: defined by method 'setDataSource' in class path resource [com/xxxx2.class] - xxxx3DataSource: defined by method 'setDataSource' in class path resource [com/xxxx3.class] Action: Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed ``` 我看了一下报错来源于 org.apache.seata.spring.boot.autoconfigure.SeataSpringFenceAutoConfiguration ``` @ConditionalOnExpression("${seata.enabled:true}") @ConditionalOnBean(type = {"javax.sql.DataSource", "org.springframework.transaction.PlatformTransactionManager"}) @ConditionalOnMissingBean(SpringFenceConfig.class) @AutoConfigureAfter({SeataCoreAutoConfiguration.class, TransactionAutoConfiguration.class}) @AutoConfigureOrder(Ordered.LOWEST_PRECEDENCE) public class SeataSpringFenceAutoConfiguration { public static final String SPRING_FENCE_DATA_SOURCE_BEAN_NAME = "seataSpringFenceDataSource"; public static final String SPRING_FENCE_TRANSACTION_MANAGER_BEAN_NAME = "seataSpringFenceTransactionManager"; @Bean @ConfigurationProperties(StarterConstants.TCC_FENCE_PREFIX) public SpringFenceConfig springFenceConfig( DataSource dataSource, PlatformTransactionManager transactionManager, @Qualifier(SPRING_FENCE_DATA_SOURCE_BEAN_NAME) @Autowired(required = false) DataSource springFenceDataSource, @Qualifier(SPRING_FENCE_TRANSACTION_MANAGER_BEAN_NAME) @Autowired(required = false) PlatformTransactionManager springFenceTransactionManager) { SpringFenceConfig springFenceConfig = new SpringFenceConfig(springFenceDataSource != null ? springFenceDataSource : dataSource, springFenceTransactionManager != null ? springFenceTransactionManager : transactionManager); ObjectHolder.INSTANCE.setObject(BEAN_NAME_SPRING_FENCE_CONFIG, springFenceConfig); return springFenceConfig; } } ``` 这里注入一个DataSource,由于区分不开到底是用哪个所以报错了。想请教下,这种是预期的吗?这个配置类是用来做什么的?有什么办法规避吗? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org