This error occurs when Spring tries to autowire a bean of type 'TransactionManager', but there are multiple beans of that type defined in the application context and none of them have been marked as primary.

To resolve this issue, you can either mark one of the beans as primary by adding the '@Primary' annotation to its definition, or you can qualify the autowired bean by specifying its name or using the '@Qualifier' annotation to specify which bean to use.

For example, if you have two beans named 'transactionManagerMysqlAccountActiveDB' and 'transactionManagerMysqlActivity', you can mark one of them as primary like this:

@Bean
@Primary
public PlatformTransactionManager transactionManagerMysqlAccountActiveDB() {
    // create and return the transaction manager for MySQL Account Active DB
}

Or you can qualify the autowired bean like this:

@Autowired
@Qualifier('transactionManagerMysqlAccountActiveDB')
private PlatformTransactionManager transactionManager;
Spring NoUniqueBeanDefinitionException: Multiple 'TransactionManager' Beans

原文地址: https://www.cveoy.top/t/topic/oKMh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录