如何使用Java而不是XML使用hbase与Spring Boot? [英] How to use hbase with Spring Boot using Java instead of XML?

查看:173
本文介绍了如何使用Java而不是XML使用hbase与Spring Boot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Spring Boot Hadoop并希望利用Spring HbaseTemplate。我的问题是,文档只有配置和设置的xml方式的信息。

我如何以及在哪里定义我的配置到java中的hbase配置,而不是到官方文档中显示的xml?

http://docs.spring.io/spring-hadoop/docs/1.0.1.RC1/reference/html/hbase.html

解决方案

那么这不是一个真正的预期答案,但我想要对它进行过多的评论。



我仔细阅读了 Spring for Apache Hadoop - 参考文档,如果它包含名称空间配置的示例和详细信息,则无法在Java配置中找到一行。



我的理解是,只有命名空间配置目前Spring for Apache Hadoop支持n。当然应该可以查看支持命名空间的类并且破解一个工作配置来找到如何用java config获得相同的结果,但老实说,我认为成本/收益率并不合理。由于它提供了在Java配置中包含xml配置文件的功能,因为它目前没有记录,所以你永远不会确定你没有忘记会在以后中断的东西。



在Spring应用程序中,我强烈建议您保留所有当前的Java配置,使用提供的命名空间将xml写入Apache Hadoop部分,并简单地为您的 @ImportResource 注释添加注释配置类。假设Spring的hadoop配置在classpath的根目录下是 hadoopContext.xml ,你可以这样写:

  @Configuration 
...
@ImportResource(classpath:/hadoopContext.xml)
public classConfig {
...
}

或者,您可以使用 @Configuration 封装器在你设法被Spring扫描的xml配置周围:

  @Configuration 
@ImportResource(classpath:/ hadoopContext.xml)
public class HadoopConfig {

}


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 configuration and setup.

How and where do I define my configuration to hbase configuration in java as opposed to the xml as show in the official docs?

http://docs.spring.io/spring-hadoop/docs/1.0.1.RC1/reference/html/hbase.html

解决方案

Well it is not really an expected answer but I want to develop it too much for a comment.

I carefully read the Spring for Apache Hadoop - Reference Documentation in its last released version, and if it does contain examples and details for namespace configuration, I could not find a single line on Java configuration.

My understanding on it is that only namespace configuration is currently supported for Spring for Apache Hadoop. It should certainly be possible to look at the classes supporting the namespace and hack a working configuration to find how to obtain same result with java config, but honestly I think the cost/gain ratio does not justify it. And as it is currently undocumented, you will never be sure that you did not forget something that will break later.

As Spring offers to include xml config files in a Java config Spring application, I would strongly advice you to keep all your present Java config, write the Apache Hadoop part in xml using the supplied namespace, and simply add an @ImportResource annotation to your configuration class. Say the spring hadoop configuration is hadoopContext.xml at the root of classpath, you could write :

@Configuration
...
@ImportResource("classpath:/hadoopContext.xml")
public classConfig {
...
}

Alternatively you can use a @Configuration wrapper around the xml config that you manage to be scanned by Spring :

@Configuration
@ImportResource("classpath:/hadoopContext.xml")
public class HadoopConfig {

}

这篇关于如何使用Java而不是XML使用hbase与Spring Boot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆