我在 Linux 上运行 Spring Batch 作业(在 Windows 上运行良好)。这是一个简单的文件存在检查,但当它确实存在时,我无法让系统找到路径/文件。Spring 的 Resource 类是否会自动知道它何时在 Linux 或 Windows 上运行?还有什么我可以做的吗
我的工作定义
<batch:job id="vendorGoalsJob" restartable="true">
<batch:step id="checkStartFileExists" next="readHeaderFiles">
<batch:tasklet ref="startFileExistsTasklet" />
</batch:step>
more steps....
</batch:job>
<bean id="startFileExistsTasklet"
class="com.blah.blah.StartFileExistsTasklet"
scope="step">
<property name="resource" value="/di/global/Users/my filename with blanks.txt" />
</bean>
小任务类:
package com.blah.blah;
import static java.lang.String.format;
import org.apache.log4j.Logger;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.core.io.Resource;
public class StartFileExistsTasklet implements Tasklet {
private static final Logger logger = Logger.getLogger(StartFileExistsTasklet.class);
private Resource resource;
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
if (!resource.isReadable()) {
logger.info(format("Resource %s not found.", resource.getFilename()));
chunkContext.getStepContext().getStepExecution().setTerminateOnly();
}
return RepeatStatus.FINISHED;
}
public void setResource(Resource resource) {
this.resource = resource;
}
}
...而且我总是收到“未找到消息”:
2013-09-26 15:47:09,342 handleStep Executing step: [checkStartFileExists] (SimpleStepHandler.java:133)
2013-09-26 15:47:09,352 execute Resource vendor-goal-trigger.txt not found.
2013-09-26 15:47:09,361 isInterrupted Step interrupted through StepExecution