Set Primary Bean for Third Libraries Code

 I have encountered a NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.transaction.transactionManager] is defined: expected single matching bean but found 2: transactionManager, springCloudTaskTransactionManager


Can use @Primary for the source code, and it's not something new. The interesting part is we can use a bridge to set Primary bean for code which isn't written by us. Here is a quick example.


@Configuration

public class BridgeConfig{


     @Primary

     @Bean

     public TransactionManager primary(@Qualifier("transactionManager") TransactionManager transactionManager){

              return transactionManager;

    }

}

Comments