How to use hbase with Spring Boot using Java instead of XML?

后端 未结 5 1604
长情又很酷
长情又很酷 2020-12-19 04:09

I have Spring Boot Hadoop and want to take advantage of the Spring HbaseTemplate. My issue is the documentation has only information about the \"xml\" way of the configurati

5条回答
  •  余生分开走
    2020-12-19 04:26

    Even though a Java-based configuration for HBase is yet not formally available (as recently as Spring Hadoop 2.2.1), there is a clean workaround. Include the relevant ZooKeeper details as properties within a Java-based Spring Hadoop configuration. Then, the hbase-configuration XML tag need not include any configuration details. By convention, it will depend on the hadoopConfiguration bean defined by the Java-based HadoopConfigConfigurer.

    @Configuration
    @EnableHadoop
    public class MapReduceConfiguration extends SpringHadoopConfigurerAdapter {
        @Override
        public void configure(HadoopConfigConfigurer config) throws Exception {
            config
                    .fileSystemUri(myConfigManager.getHadoopFsUri())
                    .resourceManagerAddress(myConfigManager.getHadoopResourceManagerAddress())
                    .withProperties()
                    .property("hbase.zookeeper.quorum", myConfigManager.getZookeeperQuorum())
                    .property("hbase.zookeeper.property.clientPort", myConfigManager.getZookeeperPort())
                    .property("hbase.client.scanner.caching", "1");
        }
    }
    

    The remaining XML configuration is agnostic to the deployment environment:

    
        
    
    

提交回复
热议问题