当前位置:网站首页>多数据源配置代码
多数据源配置代码
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);
}
}
边栏推荐
- [leetcode] 876 intermediate node of linked list
- Traversal before, during and after binary tree
- 动态规划入门一,队列的bfs(70.121.279.200)
- Xpt2046 four wire resistive touch screen
- 构建多架构镜像的最佳实践
- /Bin/ld: cannot find -lpam
- PyObject 转 char* (string)
- Solve the problem of base64encoder error
- Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics
- /bin/ld: 找不到 -lxslt
猜你喜欢
动态规划入门二(5.647.62)
[leetcode] 417 - Pacific Atlantic current problem
Introduction to dynamic planning I, BFS of queue (70.121.279.200)
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
树-二叉搜索树
隐藏在 Nebula Graph 背后的星辰大海
图数据库|Nebula Graph v3.1.0 性能报告
蚂蚁集团大规模图计算系统TuGraph通过国家级评测
PTA ladder game exercise set l2-001 inter city emergency rescue
智联招聘的基于 Nebula Graph 的推荐实践分享
随机推荐
College entrance examination admission score line crawler
Digital collection system development (program development) - Digital Collection 3D modeling economic model system development source code
6092. Replace elements in the array
[leetcode] 19 delete the penultimate node of the linked list
目标检测—利用labelimg制作自己的深度学习目标检测数据集
Ssh/scp does not prompt all activities are monitored and reported
2279. Maximum number of backpacks filled with stones
图数据库|Nebula Graph v3.1.0 性能报告
Fiddler实现手机抓包——入门
如何實現十億級離線 CSV 導入 Nebula Graph
[leetcode] 1254 - count the number of closed Islands
2279. 装满石头的背包的最大数量
Aiko ai Frontier promotion (7.2)
[leetcode] 877 stone game
/Bin/ld: cannot find -lssl
6096. 咒语和药水的成功对数
2278. Percentage of letters in string
Ant group's large-scale map computing system tugraph passed the national evaluation
Astra: could not open "2bc5/ [email protected] /6“: Failed to set USB interface
纪念成为首个 DAYU200 三方 demo 贡献者