首页>代码>SpringBoot集成HIVE小例子,采用Druid管理连接池>/src/main/java/cn/sinocon/hive/config/DruidConfig.java
package cn.sinocon.hive.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * 配置项
 * 
 * @Title: DruidConfig
 * @Description:
 * @author:Administrator
 * @date 2018年8月4日
 */
@Configuration
public class DruidConfig {

	@Autowired
	private Environment env;

	@Bean(name = "hiveJdbcDataSource")
	@Qualifier("hiveJdbcDataSource")
	public DataSource dataSource() {
		DruidDataSource dataSource = new DruidDataSource();
		dataSource.setUrl(env.getProperty("hive.jdbc"));
		dataSource.setDriverClassName(env.getProperty("hive.driver-class-name"));
		dataSource.setUsername(env.getProperty("hive.user"));
		dataSource.setPassword(env.getProperty("hive.password"));
		dataSource.setTestWhileIdle(Boolean.valueOf(env.getProperty("hive.testWhileIdle")));
		dataSource.setMaxActive(Integer.valueOf(env.getProperty("hive.max-active")));
		dataSource.setInitialSize(Integer.valueOf(env.getProperty("hive.initialSize")));
		dataSource.setRemoveAbandoned(Boolean.valueOf(env.getProperty("hive.removeAbandoned")));
		dataSource.setRemoveAbandonedTimeout(Integer.valueOf(env.getProperty("hive.removeAbandonedTimeout")));
		return dataSource;
	}

	@Bean(name = "hiveJdbcTemplate")
	public JdbcTemplate hiveJdbcTemplate(@Qualifier("hiveJdbcDataSource") DataSource dataSource) {
		return new JdbcTemplate(dataSource);
	}
}
最近下载更多
Hadoop_CPU  LV6 2023年3月11日
xiaoyuer2  LV8 2022年11月22日
mj_yya  LV41 2021年9月10日
清影恋歌  LV1 2021年9月8日
wsupsup  LV16 2021年5月21日
best2018  LV46 2021年5月17日
xgc119  LV1 2021年5月11日
Anmbos  LV1 2020年12月9日
yuanqingzhu  LV1 2020年9月28日
39617531  LV2 2020年6月8日
最近浏览更多
akittyboy  LV9 4月16日
0592lyj  LV9 1月5日
哪里的完整版  LV7 2023年12月15日
Hadoop_CPU  LV6 2023年3月11日
xiaoyuer2  LV8 2022年11月22日
dawnguarda  LV17 2022年11月7日
DoingMe 2022年11月1日
暂无贡献等级
love_颓废  LV3 2022年7月28日
gugubird  LV1 2022年6月2日
yuanhw_toto  LV1 2022年5月27日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友