美文网首页
springboot配置hbase数据源

springboot配置hbase数据源

作者: 飘_摇_ | 来源:发表于2019-12-03 10:27 被阅读0次
    pom中增加
         <dependency>
            <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-hadoop-hbase</artifactId>
                <version>2.5.0.RELEASE</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.hbase</groupId>
                <artifactId>hbase-client</artifactId>
                <version>1.1.2</version>
                <exclusions>
                    <exclusion>
                        <artifactId>slf4j-log4j12</artifactId>
                        <groupId>org.slf4j</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.data</groupId>
                <artifactId>spring-data-hadoop</artifactId>
                <version>2.5.0.RELEASE</version>
            </dependency>
    
    增加配置类
    @Configuration
    public class HBaseConfiguration {
    
        @Value("${hbase.zookeeper.quorum}")
        private String zookeeperQuorum;
    
        @Value("${hbase.zookeeper.property.clientPort}")
        private String clientPort;
    
        @Value("${zookeeper.znode.parent}")
        private String znodeParent;
    
        @Bean
        public HbaseTemplate hbaseTemplate() {
            org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
            conf.set("hbase.zookeeper.quorum", zookeeperQuorum);
            conf.set("hbase.zookeeper.property.clientPort", clientPort);
            conf.set("zookeeper.znode.parent", znodeParent);
            return new HbaseTemplate(conf);
        }
    }
    
    在application.yml中新增:
    hbase:
      zookeeper:
        quorum: node1 #在hosts文件中添加ip与hbase node的对应关系
        property:
          clientPort: 2181
    zookeeper:
      znode:
        parent: /hbase
    
    使用
     @Autowired
     private HbaseTemplate hbaseTemplate;
    

    相关文章

      网友评论

          本文标题:springboot配置hbase数据源

          本文链接:https://www.haomeiwen.com/subject/uzqfgctx.html