成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

multipledatasourceconfig-創(chuàng)新互聯(lián)

Hi Harshit S.

創(chuàng)新互聯(lián)云計算的互聯(lián)網(wǎng)服務(wù)提供商,擁有超過13年的服務(wù)器租用、川西大數(shù)據(jù)中心、云服務(wù)器、虛擬主機、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗,已先后獲得國家工業(yè)和信息化部頒發(fā)的互聯(lián)網(wǎng)數(shù)據(jù)中心業(yè)務(wù)許可證。專業(yè)提供云主機、虛擬主機、域名與空間、VPS主機、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。

project structure:

multiple datasource config as follows:

step 1:

 

step 2:add a datasource configuration class

@Configuration
public class DataSourceConfig {
// ape datasource config    @Value("${spring.ape-datasource.driver-class-name}")
private String apeDriverClassName;

    @Value("${spring.ape-datasource.url}")
private String apeDBUrl;

    @Value("${spring.ape-datasource.username}")
private String apeDBUsername;

    @Value("${spring.ape-datasource.password}")
private String apeDBPassword;

// DBQ datasource config    @Value("${spring.dbq-datasource.url}")
private String dbqDBUrl;

    @Value("${spring.dbq-datasource.username}")
private String dbqDBUsername;

    @Value("${spring.dbq-datasource.password}")
private String dbqDBPassword;

    @Value("${spring.dbq-datasource.driver-class-name}")
private String dbqDriverClassName;

    @Primary
    @Bean(name= "apeDataSource")
    @Qualifier("apeDataSource")
public DataSource apeDataSource() {
        HikariDataSource dataSource= new HikariDataSource();
        dataSource.setPoolName("ape pool");
        dataSource.setDriverClassName(apeDriverClassName);
        dataSource.setJdbcUrl(apeDBUrl);
        dataSource.setUsername(apeDBUsername);
        dataSource.setPassword(apeDBPassword);
        dataSource.setAutoCommit(true);
        dataSource.setMaximumPoolSize(20);
return dataSource;
    }

    @Bean(name= "dbqDataSource")
    @Qualifier("dbqDataSource")
public DataSource dbqDataSource() {
        HikariDataSource dataSource= new HikariDataSource();
        dataSource.setPoolName("DBQ pool");
        dataSource.setDriverClassName(dbqDriverClassName);
        dataSource.setJdbcUrl(dbqDBUrl);
        dataSource.setUsername(dbqDBUsername);
        dataSource.setPassword(dbqDBPassword);
        dataSource.setAutoCommit(true);
        dataSource.setMaximumPoolSize(20);
return dataSource;
    }

}

 Step3: add Jpa config class

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef= "apeManagerFactory",
        transactionManagerRef= "apeTransactionManager",
        basePackages= {"com.cn.ano2ape.repository.ape"}
)
public class ApeJpaConfig {
    @Autowired
    @Qualifier("apeDataSource")
private DataSource apeDataSource;

    @Autowired
private JpaProperties jpaProperties;

    @Autowired
private HibernateProperties hibernateProperties;

    @Primary
    @Bean(name= "apeEntityManager")
public EntityManager entityManager(EntityManagerFactoryBuilder builder) {
return apexaEntityManagerFactory(builder).getObject().createEntityManager();
    }

    @Primary
    @Bean(name= "apeManagerFactory")
public LocalContainerEntityManagerFactoryBean apexaEntityManagerFactory(EntityManagerFactoryBuilder builder) {
        Map<String, Object> properties = hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());
return builder.dataSource(apeDataSource).properties(properties).packages("com.cn.ano2ape.model.ape").build();
    }

    @Primary
    @Bean(name= "apeTransactionManager")
    PlatformTransactionManager apexaTransactionManager(EntityManagerFactoryBuilder builder) {
return new JpaTransactionManager(apexaEntityManagerFactory(builder).getObject());
    }
}
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
        entityManagerFactoryRef= "dbqManagerFactory",
        transactionManagerRef= "dbqTransactionManager",
        basePackages= {"com.cn.ano2ape.repository.dbq"}
)
public class DbqJpaConfig {
    @Autowired
    @Qualifier("dbqDataSource")
private DataSource dbqDataSource;

    @Autowired
private JpaProperties jpaProperties;

    @Autowired
private HibernateProperties hibernateProperties;

    @Bean(name= "dbqEntityManager")
public EntityManager entityManager(EntityManagerFactoryBuilder builder) {
return dbqEntityManagerFactory(builder).getObject().createEntityManager();
    }

    @Bean(name= "dbqManagerFactory")
public LocalContainerEntityManagerFactoryBean dbqEntityManagerFactory(EntityManagerFactoryBuilder builder) {
        Map<String, Object> properties = hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());
return builder.dataSource(dbqDataSource).properties(properties).packages("com.cn.ano2ape.model.dbq").build();
    }

    @Bean(name= "dbqTransactionManager")
    PlatformTransactionManager dbqTransactionManager(EntityManagerFactoryBuilder builder) {
return new JpaTransactionManager(dbqEntityManagerFactory(builder).getObject());
    }
}

end.

網(wǎng)站名稱:multipledatasourceconfig-創(chuàng)新互聯(lián)
當(dāng)前鏈接:http://jinyejixie.com/article42/gighc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站建設(shè)、小程序開發(fā)、網(wǎng)站設(shè)計公司、動態(tài)網(wǎng)站自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)
马关县| 石阡县| 蓝山县| 芦山县| 柯坪县| 罗定市| 阜南县| 盐城市| 修文县| 阿勒泰市| 青岛市| 丹棱县| 内江市| 淮滨县| 府谷县| 衡水市| 河津市| 舟山市| 汉阴县| 霍山县| 萝北县| 钦州市| 和硕县| 洪江市| 合水县| 红桥区| 乌鲁木齐县| 织金县| 大丰市| 东海县| 拉萨市| 昌平区| 介休市| 江口县| 东兰县| 合川市| 阿拉善左旗| 炎陵县| 华容县| 德庆县| 库尔勒市|