Is there a way to define a default transaction manager in Spring Is there a way to define a default transaction manager in Spring spring spring

Is there a way to define a default transaction manager in Spring


I was able to solve this using the @Primary annotation

  @Bean(name = "jpaTx")  public PlatformTransactionManager transactionManagerJPA() throws NamingException {    JpaTransactionManager txManager = new JpaTransactionManager(entityManagerFactory());    return txManager;  }  @Bean  @Primary  public PlatformTransactionManager txManager() throws Exception {    HibernateTransactionManager txManager = new HibernateTransactionManager(sessionFactory());    txManager.setNestedTransactionAllowed(true);    return txManager;  }


Since the same type of bean is produced from two methods, you must qualify the @Transactional annotation with the named bean. An easy way around to suite your need will be to use two different Spring application contexts. One operating with the old data source and one operating with new. Each of these contexts will have only one method producing the PlatformTransactionManager instance.