title: Configuring multiple databases in SPRING BOOT
body: <p>I'm trying to connect 2 different database for my spring boot application and this error occurs :</p>
  
  <hr>
  
  <p>APPLICATION FAILED TO START</p>
  
  <hr>
  
  <p>Description:</p>
  
  <p>Parameter 0 of method entityManagerFactory in com.SyncFibertToolSpring.SyncFibertTool.MydbDB.Config.MydbDbConfig required a bean of type 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' that could not be found.</p>
  
  <p>Action:</p>
  
  <p>Consider defining a bean of type 'org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder' in your configuration.</p>
  
  <p>Below you will find my 2 configurations classes for the databases</p>
  
  <pre><code>
  package com.SyncFibertToolSpring.SyncFibertTool.MydbDB.Config;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.boot.jdbc.DataSourceBuilder;
  import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Primary;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  
  @Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories(entityManagerFactoryRef = "mydbEntityManagerFactory",
      basePackages = {"com.SyncFibertToolSpring.SyncFibertTool.MydbDB.DAO"})
  public class MydbDbConfig {
  
  
    @Primary
    @Bean(name = "mydbDataSource")
    @ConfigurationProperties(prefix = "spring.mydb.datasource")
    public DataSource dataSource() {
      return DataSourceBuilder.create().build();
    }
  
    @Primary
    @Bean(name = "mydbEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
        EntityManagerFactoryBuilder builder, @Qualifier("mydbDataSource") DataSource dataSource) {
      return builder.dataSource(dataSource)
          .packages("com.SyncFibertToolSpring.SyncFibertTool.MydbDB.entities").
  
          build();
    }
  
    @Primary
    @Bean(name = "mydbTransactionManager")
    public PlatformTransactionManager transactionManager(
        @Qualifier("mydbEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
      return new JpaTransactionManager(entityManagerFactory);
    }
  
  }
  </code></pre>
  
  <pre><code>package com.SyncFibertToolSpring.SyncFibertTool.fibertoolSyncDB.Config;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.boot.jdbc.DataSourceBuilder;
  import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.Primary;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  
  @Configuration
  @EnableTransactionManagement
  @EnableJpaRepositories(entityManagerFactoryRef = "fibertoolSyncEntityManagerFactory",
      basePackages = {"com.SyncFibertToolSpring.SyncFibertTool.fibertoolSyncDB.DAO"})
  public class FibertToolDbConfig {
  
    @Primary
    @Bean(name = "fibertoolSyncDataSource")
    @ConfigurationProperties(prefix = "spring.fibertoolsync.datasource")
    public DataSource dataSource() {
      return DataSourceBuilder.create().build();
    }
  
    @Primary
    @Bean(name = "fibertoolSyncEntityManagerFactory")
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(
        EntityManagerFactoryBuilder builder,
        @Qualifier("fibertoolSyncDataSource") DataSource dataSource) {
      return builder.dataSource(dataSource)
          .packages("com.SyncFibertToolSpring.SyncFibertTool.fibertoolSyncDB.entities").
  
          build();
    }
  
    @Primary
    @Bean(name = "fibertoolSyncTransactionManager")
    public PlatformTransactionManager transactionManager(
        @Qualifier("fibertoolSyncEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
      return new JpaTransactionManager(entityManagerFactory);
    }
  
  
  }
  </code></pre>