title: Spring Boot EntityManagerFactoryBuilder not autowired
body: <p>In a Spring Boot application I'm trying to setup multiple database connections. I've started building the primary datasource, but I'm getting the following error on the mySqlEntityManagerFactory method.</p>
  
  <p>Could not autowire. no beans of EntityManagerFactoryBuilder</p>
  
  <pre><code>import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
  import org.springframework.boot.context.properties.ConfigurationProperties;
  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.LocalContainerEntityManagerFactoryBean;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  import org.springframework.transaction.annotation.Transactional;
  
  import javax.persistence.PersistenceContext;
  import javax.sql.DataSource;
  import java.util.HashMap;
  import java.util.Map;
  
  @Configuration
  @Transactional
  @EnableTransactionManagement
  @EnableJpaRepositories(
          basePackages = "digital.sheppard.dao",
          entityManagerFactoryRef = "entityManager",
          transactionManagerRef = "transactionManager")
  public class PrimaryDBConfig {
  
      @Bean(name="dataSource")
      @Primary
      @ConfigurationProperties(prefix = "primary.datasource.mysql")
      public DataSource mysqlDataSource() {
          return DataSourceBuilder.create().build();
      }
  
      @PersistenceContext(unitName = "primary")
      @Primary
      @Bean(name = "entityManager")
      public LocalContainerEntityManagerFactoryBean mySqlEntityManagerFactory(EntityManagerFactoryBuilder builder) {
          return builder.dataSource(mysqlDataSource()).persistenceUnit("primary").properties(jpaProperties())
                  .packages("digital.sheppard.model").build();
      }
  
      private Map&lt;String, Object&gt; jpaProperties() {
          Map&lt;String, Object&gt; props = new HashMap&lt;String, Object&gt;();
          props.put("hibernte.ejb.naming_strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
          props.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
  
          return props;
      }
  
  }
  </code></pre>
  
  <p>How would I autowire the EntityManagerFactoryBuilder?</p>
  
  <p>I'm trying to follow the code on this blog <a href="https://raymondhlee.wordpress.com/2015/10/31/configuring-multiple-jpa-entity-managers-in-spring-boot/">https://raymondhlee.wordpress.com/2015/10/31/configuring-multiple-jpa-entity-managers-in-spring-boot/</a></p>
  
  <p>Here's the main application class if it's helpful</p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
  @ComponentScan
  public class Application extends SpringBootServletInitializer {
  
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
  
  }
  </code></pre>