1
我在Linux上运行Spring批处理作业(在Windows上正常工作)。这是一个简单的文件存在检查,但我无法让系统找到路径/文件,当它确实存在。 Spring的Resource类以何种方式自动知道它在Linux或Windows上运行的时间?有没有别的东西我可以做在Linux系统上使用Spring批处理找不到文件资源
我的工作定义
<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
宾果!就是这样。谢谢。谢谢。谢谢。而且,你的解释有助于我进一步理解Spring也在做什么。 – Davidson
np,你可以找到这里描述的行为:org.springframework.core.io.DefaultResourceLoader。这个类有时用在你自己的代码中 –