我有多个与名为EntityManagers的数据库连接:
@Bean(name = "integDB")
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "integEM")
public LocalContainerEntityManagerFactoryBean integDbEntityManagerFactory(EntityManagerFactoryBuilder builder) {
....
}
如何在此处指定使用哪个实体管理器?
@Repository
public interface IntControleFilaRepository extends JpaRepository<IntControleFilaEntity, String> {
}
Spring对此抱怨: ...中的构造函数参数0需要找不到名为'entityManagerFactory'的bean。
答案 0 :(得分:0)
为每个数据库创建一个配置类,并指定与每个数据库相关联的entityManager:
@Configuration
@EnableJpaRepositories(basePackages = {"..."}, entityManagerFactoryRef = "integEM", transactionManagerRef = "integTM")
public class IntegReposConfig {
}