spring boot 2.0.2 集成hbase

maven依赖


  org.springframework.boot
  spring-boot-starter-parent
  2.0.2.RELEASE



  org.springframework.data
  spring-data-hadoop-boot
  2.5.0.RELEASE
  
     
       javax.servlet
       servlet-api
     
   


   org.springframework.data
   spring-data-hadoop
   2.5.0.RELEASE
   
      
         org.slf4j
         slf4j-log4j12
       
    
       log4j
       log4j
       
     
        javax.servlet
        servlet-api
        
     



   org.apache.hbase
   hbase-client
   1.4.4
   
      
         org.slf4j
         slf4j-log4j12
      
      
         log4j
         log4j
      
      
         javax.servlet
         servlet-api
      
   

    

configuration 配置

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.AndFileFilter;
import org.apache.commons.io.filefilter.CanReadFileFilter;
import org.apache.commons.io.filefilter.PrefixFileFilter;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.security.UserGroupInformation;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.hadoop.hbase.HbaseTemplate;

import com.hginfo.ete.common.exception.EteException;
import com.hginfo.ete.framework.data.HBaseProperties;

@Configuration
@EnableConfigurationProperties(HBaseProperties.class)
public class HBaseConfig {

    private final HBaseProperties properties;

    public HBaseConfig(HBaseProperties properties) {
        this.properties = properties;
    }

    @Bean
    public HbaseTemplate hbaseTemplate() {
        HbaseTemplate hbaseTemplate = new HbaseTemplate();
        hbaseTemplate.setConfiguration(configuration());
        hbaseTemplate.setAutoFlush(true);
        return hbaseTemplate;
    }

    public org.apache.hadoop.conf.Configuration configuration() {

        org.apache.hadoop.conf.Configuration configuration = HBaseConfiguration.create();

        Map config = properties.getConfig();
        Set keySet = config.keySet();
        for (String key : keySet) {
            configuration.set(key, config.get(key));
        }

        return configuration;
    }
    
}

HBaseProperties

@ConfigurationProperties(prefix = "hbase")
public class HBaseProperties {

    private Map config;
    
    public Map getConfig() {
        return config;
    }

    public void setConfig(Map config) {
        this.config = config;
    }
    

}

yml文件配置

hbase:
  config:
    hbase.zookeeper.quorum: 127.0.0.1,127.0.0.2,127.0.0.3
    hbase.zookeeper.property.clientPort: 2181
    fs.defaultFS: hdfs://cc-11:8020
    fs.trash.interval: 1

列出的yml配置只是最基本的,其他配置一次列入yml文件即可!

你可能感兴趣的:(spring boot 2.0.2 集成hbase)