当前位置:网站首页>Define the data source of hikaricp connection pool for bee

Define the data source of hikaricp connection pool for bee

2022-06-22 08:11:00 abckingaa

The database driver for the example is MySQL, The connection pool is HikariCP, It can be replaced with other database drivers and connection pools .

Map<String, DataSource> dataSourceMap = new HashMap<>();

//  Configure the  1  Data sources 
HikariDataSource dataSource1 = new HikariDataSource();
dataSource1.setDriverClassName("com.mysql.jdbc.Driver");
dataSource1.setJdbcUrl("jdbc:mysql://localhost:3306/ds_1");
dataSource1.setUsername("root");
dataSource1.setPassword("");
dataSourceMap.put("ds1", dataSource1);

//  Configure the  2  Data sources 
HikariDataSource dataSource2 = new HikariDataSource();
dataSource2.setDriverClassName("com.mysql.jdbc.Driver");
dataSource2.setJdbcUrl("jdbc:mysql://localhost:3306/ds_2");
dataSource2.setUsername("root");
dataSource2.setPassword("");
dataSourceMap.put("ds2", dataSource2);

Then use the following statement , It can be ORM frame Bee Set up multiple data sources .

BeeFactory.getInstance().setDataSourceMap(dataSourceMap);

原网站

版权声明
本文为[abckingaa]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220529316784.html