首页>代码>SpringBoot Hikari多数据源(Oracle、Mysql、Impala)简单实例>/springboot_hikari/springboot_hikari/src/main/java/com/example/springboot_hikari/config/HikariDataSourceConfig.java
package com.example.springboot_hikari.config; import com.zaxxer.hikari.HikariDataSource; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import javax.sql.DataSource; /** * @author Simon */ @Configuration public class HikariDataSourceConfig { @Primary @Bean(name = "impalaDataSource") @Qualifier(value = "impalaDataSource") @ConfigurationProperties(prefix = "spring.datasource.impala") public DataSource primaryDataSource() { return DataSourceBuilder.create().type(HikariDataSource.class).build(); } @Bean(name = "jdbcTemplateImpala") public JdbcTemplate jdbcTemplateImpala(@Qualifier("impalaDataSource") DataSource dataSource) { return new JdbcTemplate(dataSource); } @Bean(name = "namedJdbcTemplateImpala") public NamedParameterJdbcTemplate namedJdbcTemplateImpala( @Qualifier("impalaDataSource") DataSource dataSource) { return new NamedParameterJdbcTemplate(dataSource); } @Bean(name = "secondOracleDataSource") @Qualifier(value = "secondOracleDataSource") @ConfigurationProperties(prefix = "spring.datasource.oracle.first") public DataSource firstOracleDataSource() { return DataSourceBuilder.create().type(HikariDataSource.class).build(); } @Bean(name = "jdbcTemplateOracle1") public JdbcTemplate jdbcTemplateOracle1( @Qualifier("secondOracleDataSource") DataSource dataSource) { return new JdbcTemplate(dataSource); } @Bean(name = "thirdMysqlDataSource") @Qualifier(value = "thirdMysqlDataSource") @ConfigurationProperties(prefix = "spring.datasource.mysql.first") public DataSource firstMysqlDataSource() { return DataSourceBuilder.create().type(HikariDataSource.class).build(); } @Bean(name = "jdbcTemplateMysql1") public JdbcTemplate jdbcTemplateMysql1( @Qualifier("thirdMysqlDataSource") DataSource dataSource) { return new JdbcTemplate(dataSource); } }
最近下载更多
genyuan2014 LV3
4月27日
文成1116 LV21
2022年8月7日
CGmatt LV9
2022年6月1日
1214066599 LV8
2022年4月4日
我的心情 LV1
2022年3月11日
qizl LV8
2021年12月28日
吴文鑫 LV1
2021年12月21日
shiopaaa LV13
2021年11月8日
woldxy LV12
2021年10月22日
BestClever LV32
2021年9月11日
最近浏览更多
genyuan2014 LV3
4月27日
WBelong LV7
3月29日
kinggode LV14
2022年10月19日
wangdengzhe LV7
2022年10月5日
admire2018 LV7
2022年9月9日
wy4525 LV6
2022年8月11日
文成1116 LV21
2022年8月7日
绘飛的渔
2022年8月2日
暂无贡献等级
squarl LV10
2022年7月25日
lichengai LV7
2022年7月4日