【发布时间】:2015-03-31 16:52:46
【问题描述】:
我有一个带有自定义 ItemReader 作为委托的 MultiResourceItemReader。我面临的问题是,当我启动作业时,会一遍又一遍地读取同一个文件。
这是委托类:
public class AllegatiReader implements ResourceAwareItemReaderItemStream<Allegato> {
@PersistenceContext
protected EntityManager em;
private Resource resource;
@Override
public void close() throws ItemStreamException {
}
@Override
public void open(ExecutionContext arg0) throws ItemStreamException {
}
@Override
public void update(ExecutionContext arg0) throws ItemStreamException {
}
@Override
public Allegato read() throws Exception, UnexpectedInputException,
ParseException, NonTransientResourceException {
// DO SOMETHING ...
byte[] fileContent = new byte[(int) resource.getFile().length()];
resource.getInputStream().read(fileContent);
resource.getInputStream().close();
allegato.getFile().setFile(fileContent);
return allegato;
}
@Override
public void setResource(Resource arg0) {
this.resource = arg0;
}
}
这是我的 Spring Batch XML 配置文件:
<batch:job id="allegati" incrementer="jobParametersIncrementer">
<batch:step id="allegati-import">
<batch:tasklet>
<batch:chunk reader="allegati-reader" writer="allegati-writer" commit-interval="1"/>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="allegati-reader" class="org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
<property name="resources" value="file:#{jobParameters['FILEPATH']}/*" />
<property name="delegate" ref="allegati-filereader" />
</bean>
<bean id="allegati-writer" class="org.springframework.batch.item.database.JpaItemWriter">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="allegati-filereader" class="it.infogroup.vertenze.porting.reader.AllegatiReader" />
如何告诉 Spring Batch 移动到下一个文件?
【问题讨论】:
-
你能提供你的配置吗?
-
读完所有内容后,您的 read() 是否会返回 null?不返回 null Spring Batch 不知道 Reader 何时完成
-
@MichaelMinella 我已经添加了配置文件
-
@MichaelPralow 不,我的读者从不返回 null ......这可能是问题
标签: java spring-batch