问题描述
我在 Spring Batch 中使用 MultiResourceItemReader
来读取多个 XML 文件,我想获取当前资源.这是我的配置:
public class MultiFileResourcePartitioner extends MultiResourceItemReader{@覆盖public void update(final ExecutionContext pExecutionContext) 抛出 ItemStreamException {超级更新(pExecutionContext);if (getCurrentResource() != null && getCurrentResource().getFilename() != null) {System.out.println("更新:" + getCurrentResource().getFilename());}}}
还有我的读者:
<property name="resources" value="file:${input.directory}/*.xml"/></bean>
上面的代码正确读取 XML 文件,但方法 getCurrentResources()
返回 null.通过调试,批量进入更新方法
请帮忙!
针对这个问题有一个特定的接口叫做 ResourceAware:目的是将当前资源注入从MultiResourceItemReader
读取的对象中.
查看此主题了解更多信息.>
I am using MultiResourceItemReader
in Spring Batch for reading multiple XML files and I want to get current resource.Here is my configuration:
public class MultiFileResourcePartitioner extends MultiResourceItemReader<MyObject> {
@Override
public void update(final ExecutionContext pExecutionContext) throws ItemStreamException {
super.update(pExecutionContext);
if (getCurrentResource() != null && getCurrentResource().getFilename() != null) {
System.out.println("update:" + getCurrentResource().getFilename());
}
}
}
And my reader:
<bean id="myMultiSourceReader"
class="mypackage.MultiFileResourcePartitioner">
<property name="resources" value="file:${input.directory}/*.xml" />
</bean>
The code above read XML files correctly but the method getCurrentResources()
return null.By debugging, the batch enter to update method
Please help!
There is a specific interface for this problem called ResourceAware: it's purpouse is to inject current resource into objects read from a MultiResourceItemReader
.
Check this thread for further information.
这篇关于使用 MultiResourceItemReader Spring 批处理获取当前资源名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!