我正在尝试使用FlatFileItemReader类实现文件处理。我想要完成的是在分区中单独读取文件中的100行。我试图设置"来自"和"到"使用ExecutionContext.But我看到FlatFileItemReader没有要读取的值的parameterValues()。分区器类如下所示:
@Override public Map<String, ExecutionContext> partition(int gridSize)
{
Map<String, ExecutionContext> partitionMap = new HashMap<String, ExecutionContext>();
File dir = new File(inboundDir);
int range = 1;
int fromId = 1;
int toId = range;
if (dir.isDirectory())
{ File[] files = dir.listFiles();
for (int i = 1; i <= gridSize; i++) {
ExecutionContext context = new ExecutionContext();
context.putInt("fromId", fromId);
context.putInt("toId", toId);
context.putString("name", "Thread" + i);
partitionMap.put("partition" + i, context);
fromId = toId + 1;
toId += range;
}
}
return partitionMap;
}
我在spring上下文文件中定义的输入阅读器是:
<bean name="inventoryLoadReader" scope="step"
class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="classpath:sample01.txt" />
<property name="lineMapper" ref="inventoryLineMapper" />
<property name="linesToSkip" value="1" />
<property name="parameterValues">
<map>
<entry key="fromId" value="#{stepExecutionContext[fromId]}" />
<entry key="toId" value="#{stepExecutionContext[toId]}" />
</map>
</property>
</bean>.
我是否必须编写自定义阅读器?此外,我是否需要设置&#34;来自&#34;和&#34;到&#34;值为executionContext,以便工作。或者有更好的方法吗?
由于