Spring batch Spring批处理中的MultiResourceParitioner接受来自多个文件夹的文件
我在dataloader.properties文件中有以下配置Spring batch Spring批处理中的MultiResourceParitioner接受来自多个文件夹的文件,spring-batch,Spring Batch,我在dataloader.properties文件中有以下配置 filepath = /xx exchange = M00,M01,MF2,MF3 public class CustomM... extends MultiResourcePartitioner { // constructor with filePath and exchange argument // convert exchange argument to list of folder patterns,
filepath = /xx
exchange = M00,M01,MF2,MF3
public class CustomM... extends MultiResourcePartitioner {
// constructor with filePath and exchange argument
// convert exchange argument to list of folder patterns,
// or let it convert by spring magic
// use one of the "list all files.." methods from below
// call setResources(...)
}
<bean id="filepartitioner" class="org.springframework.batch.core.partition.support.CustomMultiResourcePartitioner">
<constructor-arg type="java.lang.String" value="${filePath}" />
<!-- spring can convert comma separated values to array and list
just look into the spring documentation -->
<constructor-arg type="java.lang.String" value="${exchange}" />
</bean>
我需要MultiResourcePartitioner来处理所有这些文件夹中的文件,例如
/xx/M00/*
/xx/M01/*
/xx/MF2/*
/xx/MF3/*
/xx
下可以有其他文件夹,但它应该只处理文件夹M00、M01、MF2、MF3中的文件
<bean id="filepartitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner">
<property name="resources" value="classpath:./${filepath}" />
</bean>
请让我知道如何在spring批处理中实现这一点。我查看了文件系统资源和资源站点Reader
api,但不知道如何将其注入到多资源分区
简单的解决方案-如果可能的话
如果图案保持稳定,你可以试一下
<bean id="filepartitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner">
<property name="resources" value="classpath:./${filepath}/M*/*" />
</bean>
定制的MultiResourcePartitioner-筛选文件夹
filepath = /xx
exchange = M00,M01,MF2,MF3
public class CustomM... extends MultiResourcePartitioner {
// constructor with filePath and exchange argument
// convert exchange argument to list of folder patterns,
// or let it convert by spring magic
// use one of the "list all files.." methods from below
// call setResources(...)
}
<bean id="filepartitioner" class="org.springframework.batch.core.partition.support.CustomMultiResourcePartitioner">
<constructor-arg type="java.lang.String" value="${filePath}" />
<!-- spring can convert comma separated values to array and list
just look into the spring documentation -->
<constructor-arg type="java.lang.String" value="${exchange}" />
</bean>
公共类自定义。。。扩展多资源分区器{
//具有filePath和exchange参数的构造函数
//将exchange参数转换为文件夹模式列表,
//或者让它通过春天的魔法转化
//使用下面的“列出所有文件…”方法之一
//调用setResources(…)
}
可以在上找到一个工作示例,检查文件-multiresourcepartitioner-filter-folders-job.xml
更多可插拔解决方案:为MultiResourcePartitioner创建资源的工厂
public class FilterFactory {
public static Resource[] getInstance(final String filePath, final List<String> acceptedFolders) {
final List<FileSystemResource> files = new ArrayList<FileSystemResource>();
yourListAllFilesButFilterFoldersMethod(files, filePath, acceptedFolders)
return files.toArray(new Resource[0]);
}
}
<bean id="resources" class="de.langmi.spring.batch.examples.playground.resource.FiltersFoldersResourceFactory" factory-method="getInstance">
<constructor-arg name="filePath" type="java.lang.String" value="${filePath}" />
<constructor-arg name="acceptedFolders" type="java.util.List" value="${acceptedFolders}" />
</bean>
公共类过滤器工厂{
公共静态资源[]getInstance(最终字符串文件路径,最终列表接受文件夹){
最终列表文件=新的ArrayList();
YourListAllFileButterFolderMethod(文件、文件路径、接受的文件夹)
返回files.toArray(新资源[0]);
}
}
可以在以下位置找到一个工作示例:检查文件-multiresourcepartitioner-filter-folders-factory-job.xml
您可以选择设置资源数组的方法以及网络上类似的解决方案,只剩下过滤器,提供的链接中有一个解决方案谢谢。模式更改。我应该从构造函数中调用setResource吗?我不明白,这是一个问题吗?非常感谢。成功了。现在,在xml配置中看到工厂方法后,我有了这个想法。