如何为Mongo数据库配置一个数据源,为H2数据库配置另一个数据源? 这是我的配置mongo存储库的代码,但DataSource将它作为javax.sql.DataSource对象。
@Configuration
@EnableJpaRepositories(entityManagerFactoryRef = "domainEntityManagerFactory",
transactionManagerRef = "domainTransactionManager", basePackageClasses = {CustomerRepositoryMongo.class})
public class CustomerConfigMongo {
@Bean
@Primary
PlatformTransactionManager domainTransactionManager() {
return new JpaTransactionManager(domainEntityManagerFactory().getObject());
}
@Bean
@Primary
LocalContainerEntityManagerFactoryBean domainEntityManagerFactory() {
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
jpaVendorAdapter.setGenerateDdl(true);
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(domainDataSource());
factoryBean.setJpaVendorAdapter(jpaVendorAdapter);
factoryBean.setPackagesToScan(Customer.class.getPackage().getName());
return factoryBean;
}
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.data.mongodb")
DataSource domainDataSource() {
DataSource dataSource = DataSourceBuilder.create().build();;
return dataSource;
}
}