错误:执行步骤org.springframework.batch.item.ItemStreamException时遇到错误:无法初始化阅读器

时间:2014-04-14 14:06:55

标签: java spring spring-batch

这是我的FlatFileItemReader配置

<beans:bean id="myFileItemReader"
    class="org.springframework.batch.item.file.FlatFileItemReader"
    p:resource="file://tmp/my-#{jobParameters[date]}/data.txt"
    p:lineMapper-ref="myLineMapper" scope="step"/>

我收到此错误

ERROR: org.springframework.batch.core.step.AbstractStep - Encountered an error executing the step
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:142)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:132)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:120)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy25.open(Unknown Source)
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96)
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:307)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:144)
    at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
    at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:163)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:142)
    at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: java.net.UnknownHostException: tmp
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at sun.net.ftp.impl.FtpClient.doConnect(FtpClient.java:958)
    at sun.net.ftp.impl.FtpClient.tryConnect(FtpClient.java:918)
    at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:1013)
    at sun.net.ftp.impl.FtpClient.connect(FtpClient.java:999)
    at sun.net.www.protocol.ftp.FtpURLConnection.connect(FtpURLConnection.java:294)
    at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:393)
    at org.springframework.core.io.UrlResource.getInputStream(UrlResource.java:125)
    at org.springframework.batch.item.file.DefaultBufferedReaderFactory.create(DefaultBufferedReaderFactory.java:34)
    at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:266)
    at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139)

1 个答案:

答案 0 :(得分:0)

我认为这不是有效的网址,因为您使用的是file://tmp/...而不是file:/tmp/...。我从未看到文件协议与双//一起使用,但我想它可能用于通过网络共享的文件,而tmp不是网络中的可解析主机。正如您所看到的,当您可能想要访问本地文件时,Spring会尝试使用FTP协议来访问该文件。