如何使用 Java 而不是 XML 将 hbase 与 Spring Boot 结合使用?

问题描述:

我有 Spring Boot Hadoop 并且想利用 Spring HbaseTemplate.我的问题是文档中只有关于配置和设置的xml"方式的信息.

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.

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

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.

我仔细阅读了Spring for Apache Hadoop - 参考文档 在其最新发布的版本中,如果它确实包含命名空间配置的示例和详细信息,我在 Java 配置上找不到任何一行.

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.

我的理解是 Spring for Apache Hadoop 目前仅支持命名空间配置.当然应该可以查看支持命名空间的类并破解工作配置以找到如何使用 java config 获得相同的结果,但老实说,我认为成本/收益比并不能证明这一点.而且由于它目前没有记录,您永远无法确定自己没有忘记一些稍后会损坏的东西.

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.

由于 Spring 提供在 Java 配置 Spring 应用程序中包含 xml 配置文件,我强烈建议您保留所有现有的 Java 配置,使用提供的命名空间在 xml 中编写 Apache Hadoop 部分,然后简单地添加一个 @ImportResource 注释到您的配置类.假设spring hadoop配置是classpath根目录下的hadoopContext.xml,你可以这样写:

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 {
...
}

或者,您可以使用 @Configuration 包装器围绕您设法由 Spring 扫描的 xml 配置:

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 {

}