当前位置:网站首页>多数据源配置代码
多数据源配置代码
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);
}
}边栏推荐
- PHP static members
- Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory
- [development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
- 【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
- 【小白聊云】中小企业容器化改造建议
- Strings and arrays
- 基于 Nebula Graph 构建百亿关系知识图谱实践
- The task cannot be submitted after the installation of flick is completed
- [leetcode] 1254 - count the number of closed Islands
- 已知兩種遍曆序列構造二叉樹
猜你喜欢

动态规划入门二(5.647.62)
![[leetcode] 1905 statistics sub Island](/img/82/d2f7b829f5beb7f9f1eabe8d101ecb.png)
[leetcode] 1905 statistics sub Island

Two traversal sequences are known to construct binary trees

可视化技术在 Nebula Graph 中的应用

Experiment collection of University "Fundamentals of circuit analysis". Experiment 7 - Research on sinusoidal steady-state circuit
![[experience cloud] how to get the metadata of experience cloud in vscode](/img/45/012c2265402ba1b44f4497f468bc61.png)
[experience cloud] how to get the metadata of experience cloud in vscode

Thoroughly understand browser strong cache and negotiation cache

Postgressql stream replication active / standby switchover primary database no read / write downtime scenario

【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData

《大学“电路分析基础”课程实验合集.实验四》丨线性电路特性的研究
随机推荐
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
Fiddler realizes mobile packet capturing - getting started
6095. 强密码检验器 II
Pyobject to char* (string)
How to use percona tool to add fields to MySQL table after interruption
/bin/ld: 找不到 -lxslt
Use ffmpeg command line to push UDP and RTP streams (H264 and TS), and ffplay receives
《大学“电路分析基础”课程实验合集.实验七》丨正弦稳态电路的研究
[leetcode] 1905 statistics sub Island
Comparison between rstan Bayesian regression model and standard linear regression model of R language MCMC
SQL FOREIGN KEY
使用 percona 工具给 MySQL 表加字段中断后该如何操作
Folium, diagnosis and close contact trajectory above
奥比中光 astra: Could not open “2bc5/[email protected]/6“: Failed to set USB interface
6090. 极大极小游戏
[leetcode] 695 - maximum area of the island
/bin/ld: 找不到 -lxml2
2303. 计算应缴税款总额
How to import a billion level offline CSV into Nepal graph
PyObject 转 char* (string)