0

我试图使用 spring data hadoop 向 HDFS 写一个简单的文本。但我在写作时遇到了一个未知问题。

线程“主”org.springframework.data.hadoop.store.StoreException 中的异常:存储输出上下文尚未初始化;嵌套异常是 java.io.IOException: Unexpected HTTP response: code=404 != 200, op=GETFILESTATUS, message=Not Found at org.springframework.data.hadoop.store.support.OutputStoreObjectSupport.getOutputContext(OutputStoreObjectSupport.java:135 ) 在 org.springframework.data.hadoop.store.output.TextFileWriter.write(TextFileWriter.java:132) 在 org.springframework.data.hadoop.store.output.AbstractDataStreamWriter.getOutput(AbstractDataStreamWriter.java:131) 在 com。 com.mstack.app.MainApp.main(MainApp.java:32) 处的 mstack.app.MainApp.someMethod(MainApp.java:37) 原因:java.io.IOException:意外的 HTTP 响应:code=404 != 200 , op=GETFILESTATUS, message=在 org.apache 上找不到。

我的 application-context.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/hadoop"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:hdp="http://www.springframework.org/schema/hadoop" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">


    <hdp:configuration id="hadoopConfigBean">
        fs.defaultFS=${hdp.fs}
    </hdp:configuration>

    <context:annotation-config />
    <beans:bean id="textFileWriter"
        class="org.springframework.data.hadoop.store.output.TextFileWriter">
        <beans:constructor-arg index="0" ref="hadoopConfigBean"></beans:constructor-arg>
        <beans:constructor-arg index="1"
            type="org.apache.hadoop.fs.Path" value="/user/mhduser"></beans:constructor-arg>
        <beans:constructor-arg index="2" type="org.springframework.data.hadoop.store.codec.CodecInfo" >
        <beans:null></beans:null>
        </beans:constructor-arg>
    </beans:bean>

    <context:property-placeholder location="hadoop-configs.properties" />
</beans:beans>

主要课程:-

public class MainApp {

    @Autowired
    TextFileWriter textFileWriter;

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/application-context.xml",
                MainApp.class);
        System.out.println("Context loaded...");
        MainApp obj = new MainApp();
        context.getAutowireCapableBeanFactory().autowireBean(obj);
        obj.someMethod();
    }

    private void someMethod() {
        try {
            textFileWriter.write("Something");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

任何帮助,将不胜感激 !谢谢

4

1 回答 1

1

我们在这里有一些示例https://github.com/spring-projects/spring-hadoop-samples。没有什么特别的想法,所以我创建了一个基于 Spring Boot 的简单 gist,可以通过它的 CLI 运行。https://gist.github.com/jvalkeal/8145f0618f25c1d25d19f4e1e89de1e6

还值得看看我们在单元测试中做了什么https://github.com/spring-projects/spring-hadoop/tree/master/spring-hadoop-store/src/test/java/org/springframework/data/hadoop/店铺

于 2016-04-21T14:43:35.493 回答