当前位置:网站首页>多数据源配置代码
多数据源配置代码
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);
}
}
边栏推荐
猜你喜欢
《大学“电路分析基础”课程实验合集.实验五》丨线性有源二端网络等效电路的研究
Aike AI frontier promotion (7.2)
图数据库|Nebula Graph v3.1.0 性能报告
[experience cloud] how to get the metadata of experience cloud in vscode
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
Introduction to Dynamic Planning II (5.647.62)
[development environment] install Visual Studio Ultimate 2013 development environment (download software | install software | run software)
Soul torture, what is AQS???
Thoroughly understand browser strong cache and negotiation cache
爱可可AI前沿推介(7.2)
随机推荐
Wise target detection 23 - pytoch builds SSD target detection platform
Aike AI frontier promotion (7.2)
/bin/ld: 找不到 -lpam
/Bin/ld: cannot find -lxslt
【Experience Cloud】如何在VsCode中取得Experience Cloud的MetaData
目标检测—利用labelimg制作自己的深度学习目标检测数据集
Solve the problem of base64encoder error
Cultural scores of summer college entrance examination
SQL修改语句
Make p12 certificate [easy to understand]
[leetcode] 486 predict winners
动态规划入门二(5.647.62)
(5) Flink's table API and SQL update mode and Kafka connector case
《大学“电路分析基础”课程实验合集.实验四》丨线性电路特性的研究
[leetcode] 877 stone game
How to use percona tool to add fields to MySQL table after interruption
隐藏在 Nebula Graph 背后的星辰大海
【idea】推荐一个idea翻译插件:Translation「建议收藏」
/Bin/ld: cannot find -lxml2
Experiment collection of University "Fundamentals of circuit analysis". Experiment 4 - Research on linear circuit characteristics