亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring Boot,Spring Data JPA,帶有多個DataSources

Spring Boot,Spring Data JPA,帶有多個DataSources

qq_遁去的一_1 2019-09-02 08:31:49
我正在嘗試使用Spring Boot和Spring Data JPA將每個@Repositories連接到不同的DataSource。我使用以下內容http://xantorohara.blogspot.com/2013/11/spring-boot-jdbc-with-multiple.html作為參考。以下是我試圖使用Spring Data JPA實現類似解決方案時使用的代碼。CustomerDbConfig.java(第一個數據源連接)@Configuration@EnableJpaRepositories(        entityManagerFactoryRef = "orderEntityManager",        transactionManagerRef = "orderTransactionManager",        basePackages = {"com.mm.repository.customer"})public class CustomerDbConfig {    @Bean(name = "customerEntityManager")    public LocalContainerEntityManagerFactoryBean entityManagerFactory(){        LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();        em.setDataSource(dataSource());        em.setPackagesToScan(new String[] {"com.mm.domain.customer"});        JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();        em.setJpaVendorAdapter(vendorAdapter);        em.setJpaProperties(additionalJpaProperties());        em.setPersistenceUnitName("customerPersistence");        em.setPackagesToScan("com.mm.domain.customer");        return em;    }    Properties additionalJpaProperties(){        Properties properties = new Properties();        properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");        properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");        properties.setProperty("hibernate.show_sql", "true");        return properties;    }    @Bean    public DataSource dataSource(){        return DataSourceBuilder.create()                .url("jdbc:h2:mem:customer:H2")                .driverClassName("org.h2.Driver")                .username("sa")                .password("")                .build();    }   
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 1396 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號