title: spring boot secondary datasource with primary auto configured
body: <p>i am trying to configure two jpa datasource , i did same as <a href="https://github.com/spring-projects/spring-data-examples" rel="nofollow">this example</a> , every thing is good but is it possible to keep the auto configuration done automatically and just add a new one without having to create <code>LocalContainerEntityManagerFactoryBean</code> manually.</p>
  
  <pre><code> @Primary
      @Bean(name = "dataSource")
      @ConfigurationProperties(prefix="spring.datasource")
      public DataSource dataSource() {
          return DataSourceBuilder.create().build();
      }
  
  @Bean
  PlatformTransactionManager transactionManager() {
      return new JpaTransactionManager(entityManagerFactory().getObject());
  }
  
  @Bean
  LocalContainerEntityManagerFactoryBean entityManagerFactory() {
  
      HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
      jpaVendorAdapter.setGenerateDdl(false);
  
      LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
  
      factoryBean.setDataSource(dataSource());
      factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
  
      factoryBean.setPackagesToScan("com.xxxxxxxx.common.domain","com.xxxxxxx.tekram.cdrserver.domain");
  
      return factoryBean;
  }
  </code></pre>