2013-05-07 88 views
1

我在http://blog.springsource.org/2012/02/29/introducing-spring-hadoop/配置HADOOP工作与Javaconfig

以下,现在春天HADOOP的介绍页的示例配置是基于XML的。以下代码描述了wordCount示例。

<!-- define the job --> 
<hdp:job id="word-count" 
    input-path="/input/" output-path="/ouput/" 
    mapper="org.apache.hadoop.examples.WordCount.TokenizerMapper" 
    reducer="org.apache.hadoop.examples.WordCount.IntSumReducer"/> 

<!-- execute the job --> 
<bean id="runner" class="org.springframework.data.hadoop.mapreduce.JobRunner" 
       p:jobs-ref="word-count"/> 

有配置与Javaconfig这个例子的方法吗?

回答

-1

您可以通过使用Configuration对象的各种.set()方法,像这样以编程方式设置Hadoop配置:

Configuration conf = new Configuration(); 
conf.set("example.foo", "bar"); 
+1

这使得该解决方案少弹性。我的意思是带有注释的javaconfig解决方案,就像下面的帖子http://www.mkyong.com/spring3/spring-3-javaconfig-example/ – 2013-05-07 11:21:01

+0

据我所知基于注解的配置系统不存在,这是我从java内部知道的唯一解决方案。如果你喜欢,你可以通过'-Dexample.foo = bar'在命令行上设置它们,尽管当你开始你的hadoop作业时。 – Quetzalcoatl 2013-05-07 11:43:58

+0

当前版本的Spring for Hadoop 1.0尚不支持Hadoop组件的注释。从此版本开始,只有配置的方式是使用.xml文件 – 2013-05-07 14:50:34

0
@Configuration 
@EnableHadoop 
@PropertySource(value={"classpath:config/hadoop.properties"}) 
public class HadoopConfiguration extends SpringHadoopConfigurerAdapter { 
@Override 
public void configure(HadoopConfigConfigurer config) throws Exception { 
    Properties props = new Properties(); 
    config.fileSystemUri("hdfs://"); 
    config.withProperties(props).property("propkey", "propvalue").and(); 
} 
}