Skip to content

Support specifying resource locations using a pattern in MultiResourceItemReaderBuilder #5056

@benelog

Description

@benelog

MultiResourceItemReaderBuilder currently allows setting resources via the resources(Resource[]) method:

return new MultiResourceItemReaderBuilder<User>()
    .delegate(fileReader)
    .resources(new Resource[] { r1, r2, r3, r4 })
    .name("multiFileReader")
    .build();

In many cases, multiple files need to be specified using a pattern.
While this can be achieved manually using the PathMatchingResourcePatternResolver class:

var resourcePatternResolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resourcePatternResolver.getResources("file:/home/logs/*.csv");

return new MultiResourceItemReaderBuilder<User>()
    .delegate(fileReader)
    .resources(resources)
    .name("multiFileReader")
    .build();

It would be more convenient if MultiResourceItemReaderBuilder itself could directly accept a resource pattern.
In older XML-based configurations in Spring Framework , resource arrays defined with patterns were automatically resolved by PathMatchingResourcePatternResolver.
Given that background, it feels natural to provide a similar capability in the builder API.

I’d like to propose adding a method like MultiResourceItemReaderBuilder.resourcesPattern(String) to support this use case:

return new MultiResourceItemReaderBuilder<User>()
    .delegate(fileReader)
    .filesPattern("/home/logs/*.csv")
    .name("multiFileReader")
    .build();

Since this would be a relatively simple enhancement, I’d be happy to submit a Pull Request myself if the team agrees with the need for it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions