每当我使用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
答案 0 :(得分:1)
<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中打开输入流以解析自定义资源,并在读取后关闭。来自get
的方法FileSystem
随后重新加载已关闭的相同流,并再次读取抛出IOException: stream closed
错误。
与github上的示例类似,解决方法是使用Spring属性和SpEl(Spring表达式语言)来替换必要字段所需的配置。另一个选项可能是编写您自己的ConfigurationFactoryBean
,它将使用现有的Configuration
实例作为父实例,并将资源添加为URL。
希望这有点帮助。
答案 1 :(得分:1)
这已在主干中修复,将在下一个里程碑中提供。有关详细信息,请参阅春季论坛帖子[1]。