NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined: expected single matching bean NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined: expected single matching bean spring spring

NoUniqueBeanDefinitionException: No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined: expected single matching bean


I think you should be naming your LocalContainerEntityManagerFactoryBean's in both configurations. So it should look like:

@Bean(name = "nextGenEntityManagerFactory")@Primarypublic LocalContainerEntityManagerFactoryBean nextGenEntityManagerFactory() {

for the first one and

@Bean(name = "gatcLimsEntityManagerFactory") public LocalContainerEntityManagerFactoryBean gatcLimsEntityManagerFactory() {

for the second.


This exception can also be tackled by exluding JPA autoconfiguration. Usually when there are two Entity Managers the configuration is done manualy anyway, so there is no point in relying on autoconfiguration for that.

DataSourceAutoconfiguration should be excluded and everything which inherits from JpaBaseConfiguration

@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration} public class MySpringApp() {}

or

@SpringBootAutoconfiguration(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration)public class MySpringApp() {}