diff --git a/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java b/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java index 4853303ae0..13f8f4b27c 100644 --- a/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java +++ b/spring-jpa/src/main/java/org/baeldung/config/ProductConfig.java @@ -29,8 +29,10 @@ public class ProductConfig { super(); } - @Bean(name = "productEntityManager") - public LocalContainerEntityManagerFactoryBean productEntityManagerFactory() { + // + + @Bean + public LocalContainerEntityManagerFactoryBean productEntityManager() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(productDataSource()); em.setPackagesToScan(new String[] { "org.baeldung.persistence.multiple.model.product" }); @@ -56,10 +58,10 @@ public class ProductConfig { return dataSource; } - @Bean(name = "productTransactionManager") - public PlatformTransactionManager transactionManager() { + @Bean + public PlatformTransactionManager productTransactionManager() { final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(productEntityManagerFactory().getObject()); + transactionManager.setEntityManagerFactory(productEntityManager().getObject()); return transactionManager; } diff --git a/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java b/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java index 379e8485ce..8e85f5d8e0 100644 --- a/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java +++ b/spring-jpa/src/main/java/org/baeldung/config/UserConfig.java @@ -30,8 +30,11 @@ public class UserConfig { super(); } - @Bean(name = "userEntityManager") - public LocalContainerEntityManagerFactoryBean userEntityManagerFactory() { + // + + @Primary + @Bean + public LocalContainerEntityManagerFactoryBean userEntityManager() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(userDataSource()); em.setPackagesToScan(new String[] { "org.baeldung.persistence.multiple.model.user" }); @@ -46,6 +49,7 @@ public class UserConfig { return em; } + @Primary @Bean public DataSource userDataSource() { final DriverManagerDataSource dataSource = new DriverManagerDataSource(); @@ -58,10 +62,10 @@ public class UserConfig { } @Primary - @Bean(name = "userTransactionManager") - public PlatformTransactionManager transactionManager() { + @Bean + public PlatformTransactionManager userTransactionManager() { final JpaTransactionManager transactionManager = new JpaTransactionManager(); - transactionManager.setEntityManagerFactory(userEntityManagerFactory().getObject()); + transactionManager.setEntityManagerFactory(userEntityManager().getObject()); return transactionManager; }