Spring Batch 中对读取 zip 下的多个文件的任何支持

发布于 2025-01-15 23:27:04 字数 437 浏览 6 评论 0 原文

我正在寻找根据位置从多个文件加载人员记录。 Spring批处理是否有任何简单的支持来加载多个名为location weise的文件? Easy Country_people.zip -> Location1(文件夹1)包含3个文本文件(people_education.txt、people_address.txt、people_invenue.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)

I am looking for loading people records from multiple files based on location. Is there any easy support by Spring batch to load multiple files named location weise?
Easy Country_people.zip
-> Location1 (folder1) containing 3 text files(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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软糖 2025-01-22 23:27:04

您可以尝试使用 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;
    }
}

You can try using Partitioner to get the data from multiple files

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

Or 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;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文