Skip to content

Add a builder for ResourcesItemReader with support for specifying files via a pattern #5487

Description

@benelog

Expected Behavior

A builder for ResourcesItemReader, consistent with the other readers and writers in the org.springframework.batch.infrastructure.item.file.builder package, that also supports specifying the resources with a file pattern:

ResourcesItemReader reader = new ResourcesItemReaderBuilder()
    .filesPattern("/data/inputs/*.csv")
    .name("resourcesReader")
    .build();

Current Behavior

ResourcesItemReader is the only reader in the org.springframework.batch.infrastructure.item.file package without a builder. It can only be configured through the default constructor and setResources(Resource[]).

Its Javadoc even suggests configuring it with a pattern ("Hint: use a pattern to configure."), which worked out of the box in XML configuration thanks to ResourceArrayPropertyEditor. In Java configuration, however, resolving the pattern is left to the user:

var resourcePatternResolver = new PathMatchingResourcePatternResolver();
ResourcesItemReader reader = new ResourcesItemReader();
reader.setResources(resourcePatternResolver.getResources("file:/data/inputs/*.csv"));
reader.setName("resourcesReader");

Context

This is a companion of #5056, which proposes the same pattern support for MultiResourceItemReaderBuilder (PR #5071). The proposed filesPattern(String) method follows the same naming and semantics, so the two builders would stay consistent.

I will submit a pull request for this shortly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions