簡體   English   中英

Spring中任意支持批量讀取zip下的多個文件

[英]Any support in Spring Batch for reading multiple files under zip

我正在尋找根據位置從多個文件加載人員記錄。 Spring 是否支持批量加載名為 location weise 的多個文件? Easy Country_people.zip -> Location1 (folder1) 包含 3 個文本文件(people_education.txt、people_address.txt、people_income.txt)

 -> Location2 (folder2) containing 3 text files(people_education.txt, people_address.txt, people_income.txt)

 -> Location3 (folder3) containing 3 text files(people_education.txt, people_address.txt, people_income.txt)

您可以嘗試使用Partitioner從多個文件中獲取數據

https://docs.spring.io/spring-batch/docs/current/reference/html/scalability.html#partitioning

或者https://docs.spring.io/spring-framework/docs/4.0.0.RELEASE/javadoc-api/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html

https://docs.spring.io/spring-batch/docs/current/api/org/springframework/batch/item/file/MultiResourceItemReader.html

public class CustomMultiResourcePartitioner implements Partitioner {
 
    @Override
    public Map<String, ExecutionContext> partition(int gridSize) {
        Map<String, ExecutionContext> map = new HashMap<>(gridSize);
        int i = 0, k = 1;
        for (Resource resource : resources) {
            ExecutionContext context = new ExecutionContext();
            Assert.state(resource.exists(), "Resource does not exist: " 
              + resource);
            context.putString(keyName, resource.getFilename());
            context.putString("opFileName", "output"+k+++".xml");
            map.put(PARTITION_KEY + i, context);
            i++;
        }
        return map;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM