Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

5.26. Spring boot with Apache Hive

5.26.1. Maven

			
<properties>  
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>  
  
<dependencies>  
    <dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-jdbc</artifactId>  
    </dependency>  
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-hadoop</artifactId>
        <version>2.4.0.RELEASE</version>
    </dependency> 
	<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-jdbc -->
	<dependency>
	    <groupId>org.apache.hive</groupId>
	    <artifactId>hive-jdbc</artifactId>
	    <version>2.1.1</version>
	</dependency>
	<dependency>  
        <groupId>com.alibaba</groupId>  
        <artifactId>druid</artifactId>  
        <version>1.1.0</version>  
    </dependency> 
</dependencies>  
			
			

5.26.2. application.properties

hive 數據源配置項

			
hive.url=jdbc:hive2://172.16.0.10:10000/default
hive.type: com.alibaba.druid.pool.DruidDataSource
hive.driver-class-name: org.apache.hive.jdbc.HiveDriver
hive.username=hive
hive.password=hive
			
			

如果使用 yaml 格式 application.yml 配置如下

			 
hive:  
  url: jdbc:hive2://172.16.0.10:10000/default
  driver-class-name: org.apache.hive.jdbc.HiveDriver 
  type: com.alibaba.druid.pool.DruidDataSource
  username: hive
  password: hive
			
			

5.26.3. Configuration

			
package cn.netkiller.api.config; 

@Configuration  
public class HiveDataSource {  
      
    @Autowired  
    private Environment env;  
  
    @Bean(name = "hiveJdbcDataSource")
    @Qualifier("hiveJdbcDataSource")
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(env.getProperty("hive.url"));
        dataSource.setDriverClassName(env.getProperty("hive.driver-class-name"));
        dataSource.setUsername(env.getProperty("hive.username"));
        dataSource.setPassword(env.getProperty("hive.password"));
        return dataSource;
    }

    @Bean(name = "hiveJdbcTemplate") 
    public JdbcTemplate hiveJdbcTemplate(@Qualifier("hiveJdbcDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}