【问题标题】:IOException using Spring Data Hadoop Classpath ResourcesIOException 使用 Spring Data Hadoop 类路径资源
【发布时间】:2012-03-05 13:44:50
【问题描述】:

每当我使用 Spring Data Hadoop 命名空间指定资源时,应用程序在加载指定的文件时会抛出 IOException。该文件确实存在并且格式有效。

Spring Data Hadoop XML 配置:

启动时的堆栈跟踪:

Caused by: java.lang.RuntimeException: java.io.IOException: Stream closed
    at org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:1231)
    at org.apache.hadoop.conf.Configuration.loadResources(Configuration.java:1103)
    at org.apache.hadoop.conf.Configuration.getProps(Configuration.java:1037)
    at org.apache.hadoop.conf.Configuration.get(Configuration.java:415)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:860)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1380)
    at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1404)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:254)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:123)
    at com.mendeley.swets.config.HdfsConfig.fileSystem(HdfsConfig.java:28)
    at com.mendeley.swets.config.HdfsConfig$$EnhancerByCGLIB$$38b1feb7.CGLIB$fileSystem$0(<generated>)
    at com.mendeley.swets.config.HdfsConfig$$EnhancerByCGLIB$$38b1feb7$$FastClassByCGLIB$$3c3c119d.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:280)
    at com.mendeley.swets.config.HdfsConfig$$EnhancerByCGLIB$$38b1feb7.fileSystem(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:149)
    ... 41 more
Caused by: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getBufIfOpen(BufferedInputStream.java:145)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:189)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2932)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:704)
    at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
    at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
    at org.apache.hadoop.conf.Configuration.loadResource(Configuration.java:1162)
    ... 61 more

【问题讨论】:

  • Spring Data Hadoop 处于里程碑 1 中,因此它可能包含问题。你也在 Spring 论坛上问过吗?
  • @Luciano - 我确实做到了,但没有回复:(
  • 问题 - 您是否在 Spring 中使用 classpath:file.xml 表示法指定 xml 文件?在读取一次 InputStream 然后再次读取之前,我遇到过 FileSystem 的问题(我忘记了导致这种情况的“完美风暴”情况),导致 IOException。

标签: java spring hadoop ioexception spring-data


【解决方案1】:

这已在主干中修复,并将在下一个里程碑中可用。有关详细信息,请参阅春季论坛帖子 [1]。

[1]http://forum.springsource.org/showthread.php?123777-IOException-when-using-lt-hadoop-configuration-resources-quot

【讨论】:

    【解决方案2】:

    克里斯实际上是对的。我遇到了类似的问题(IOException:流已关闭),该问题是由从陈旧的流中读取引起的。我猜,Deejay,你正在使用类似的东西从你的类路径中读取自定义资源:

    <hdp:configuration resources="classpath:/custom-site.xml"/>
    

    ,然后获取一个文件系统为FileSystem.get(conf)

    在使用调试器一段时间后,问题似乎是由 Spring 的 ConfigurationFactoryBean 和 Apache Hadoop 的 Configuration 对象的组合引起的。如果你在 github 上查看 Spring Hadoop 的源代码(是的,那里有),Spring Hadoop 看起来就像是 Spring Settings 和 Apache Hadoop API 的组合。

    在 Spring 中打开一个输入流来解析自定义资源,并在读取后关闭。来自FileSystem 的方法get 随后重新加载已关闭的相同流,并再次读取并抛出IOException: stream closed 错误。

    一种解决方法,类似于 github 上的示例,是使用 Spring 属性和 SpEl(Spring 表达式语言)来替换必要字段所需的配置。另一种选择可能是编写自己的ConfigurationFactoryBean,它将使用现有实例作为父实例创建一个新的Configuration 实例,并将资源添加为URL。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 2011-12-15
      • 2015-11-09
      • 2016-06-15
      • 1970-01-01
      相关资源
      最近更新 更多