Spring Boot注释中的hdp:配置相当于什么?

时间:2014-04-22 05:03:37

标签: java spring hbase

我希望能够在春天使用HBase。我能看到的文件有一些说法:

<hdp:configuration>
        fs.default.name=${hd.fs}
        mapred.job.tracker=${mapred.job.tracker}
        hbase.zookeeper.quorum=${hbase.zookeeper.quorum}
</hdp:configuration>

我如何在我的Application.java中以编程方式使用它?似乎没有关于如何使用HBaseTemplate连接到hbase的示例或文档。按照另一篇文章中的建议查看以下存储库没有与hbase相关的示例:

https://github.com/spring-projects/spring-hadoop-samples

3 个答案:

答案 0 :(得分:0)

目前我还没有为hdp:configuration找到基于注释的配置,但是对于我的Spring-Hadoop项目,我已经为haddop配置创建了一个xml hadoop-context.xml 并导入它在Config.java中如下

    @Configuration
    @ImportResource ( "hadoop-context.xml")
    public class Config
    {

     @Autowired
     private org.apache.hadoop.conf.Configuration hadoopConfiguration;
    }

最有可能的是,在你的情况下解决问题会有所帮助。

答案 1 :(得分:0)

我知道问题已经过时了,但我刚刚遇到这个问题并且能够解决。实现SpringHadoopConfigurerAdapter,如:

@Configuration
@EnableHadoop
public class HadoopConfiguration extends SpringHadoopConfigurerAdapter {
    @Autowired
    private ResourceLoader resourceLoader;

    @Override
    public void configure(HadoopConfigConfigurer config) throws Exception {

        org.apache.hadoop.conf.Configuration conf = getHadoopConfig("classpath:/mapred-site.xml");

        config
                .withResources()
                .resource("classpath:/yarn-site.xml")
                .resource("classpath:/hbase-site.xml")
                .resource("classpath:/mapred-site.xml")
                .and()
                .withProperties()
                .property("mapreduce.app-submission.cross-platform", "true")
                .property("mapreduce.framework.name", "yarn")
                .property("mapreduce.application.framework.path", "")
                .property("mapreduce.map.log.level", "INFO")
                .property("mapreduce.reduce.log.level", "INFO")
                .property("hbase.client.scanner.caching", "1")
                .property("hbase.client.scanner.timeout.period", "300000")
                .property("hbase.rpc.timeout", "300000");

    }

    private org.apache.hadoop.conf.Configuration getHadoopConfig(String mrSiteFile) throws IOException {
        Resource mapRedSite = resourceLoader.getResource(mrSiteFile);
        org.apache.hadoop.conf.Configuration conf = new org.apache.hadoop.conf.Configuration();
        conf.addResource(mapRedSite.getInputStream());
        return conf;
    }
}

然后您就可以注入HadoopConfiguration:

@Autowired
org.apache.hadoop.conf.Configuration hadoopConfiguration;

答案 2 :(得分:-1)

您是否看过这个:http://docs.spring.io/spring-hadoop/docs/2.0.1.RELEASE/reference/html/hbase.html?我相信这给你相当于HBaseConfiguration配置。您也可以在那里添加您的属性。如果没有帮助,请回复。

相关问题