当前位置:网站首页>多数据源配置代码
多数据源配置代码
2022-07-02 12:28:00 【lvhui321】
@Configuration
public class ImpalaDataSourceConfig {
@Value("${impala.drive_class_name}")
private String driverClassName;
@Value("${impala.jdbc_url}")
private String jdbcUrl;
@Value("${impala.mapper-locations}")
private String locations;
@Bean(name = "impalaDataSource")
@Qualifier(value = "impalaDataSource")
public DataSource primaryDataSource() {
HikariConfig config = new HikariConfig();
config.setDriverClassName(driverClassName);
config.setJdbcUrl(jdbcUrl);
HikariDataSource dataSource = new HikariDataSource(config);
return dataSource;
}
@Bean(name = "impalaSqlSessionFactory")
public SqlSessionFactory impalaSqlSessionFactory(@Qualifier("impalaDataSource") DataSource dataSource) throws Exception {
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setDataSource(dataSource);
//此处创建一个Configuration 注意包不要引错了
org.apache.ibatis.session.Configuration configuration=new org.apache.ibatis.session.Configuration();
//配置日志实现
configuration.setLogImpl(StdOutImpl.class);
//此处可以添加其他mybatis配置 例如转驼峰命名
configuration.setMapUnderscoreToCamelCase(true);
//bena工厂装载上面配置的Configuration
bean.setConfiguration(configuration);
//设置mapper配置文件
bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(locations));
return bean.getObject();
}
/**创建SqlSessionTemplate*/
@Bean(name = "impalaSqlSessionTemplate")
public SqlSessionTemplate impalaSqlSessionTemplate(@Qualifier("impalaSqlSessionFactory") SqlSessionFactory sqlSessionFactory){
return new SqlSessionTemplate(sqlSessionFactory);
}
}边栏推荐
- Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics
- Name of institution approved in advance
- /Bin/ld: cannot find -lpam
- [2. Basics of Delphi grammar] 3 Object Pascal constants and variables
- 【idea】推荐一个idea翻译插件:Translation「建议收藏」
- 二叉树前,中,后序遍历
- Demo of converting point cloud coordinates to world coordinates
- 睿智的目标检测23——Pytorch搭建SSD目标检测平台
- 数字藏品系统开发(程序开发)丨数字藏品3D建模经济模式系统开发源码
- PTA ladder game exercise set l2-001 inter city emergency rescue
猜你喜欢
![[salesforce] how to confirm your salesforce version?](/img/ce/4c844b1b686397faa1b6aa3d57e034.png)
[salesforce] how to confirm your salesforce version?

已知两种遍历序列构造二叉树

The outline dimension function application of small motherboard

如何实现十亿级离线 CSV 导入 Nebula Graph

【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
![[leetcode] 1254 - count the number of closed Islands](/img/84/f888ae0e164951cd9623fb3bf4a984.png)
[leetcode] 1254 - count the number of closed Islands

Pattern matching extraction of specific subgraphs in graphx graph Computing Practice

Introduction to Dynamic Planning II (5.647.62)

Aike AI frontier promotion (7.2)

愛可可AI前沿推介(7.2)
随机推荐
6092. 替换数组中的元素
beforeEach
[leetcode] 877 stone game
/bin/ld: 找不到 -llz4
6091. Divide the array so that the maximum difference is K
List of sergeant schools
Name of institution approved in advance
【小白聊云】中小企业容器化改造建议
[leetcode] 283 move zero
lseek 出错
[leetcode] 1162 map analysis
(万字精华知识总结)Shell脚本编程基础知识
College entrance examination score line climbing
树-二叉搜索树
QVariant与Json的各种纠葛——Qt
ssh/scp 使不提示 All activities are monitored and reported.
Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
College entrance examination admission score line crawler
Xpt2046 four wire resistive touch screen
Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface