Skip to content

Conversation

@benelog
Copy link
Contributor

@benelog benelog commented Nov 1, 2025

It resolves #5056

The method name intentionally uses filesPattern instead of resourcesPattern, since in most cases the target resources are file-based. Internally, MultiResourceItemReaderBuilder.build() resolves resources using PathMatchingResourcePatternResolver.getResources(String) with a "file:" prefix, which aligns naturally with this naming choice.

I also attempted to add a test case to cover the catch block in the following code segment:

try {
	Resource[] resources = patternResolver.getResources("file:" + this.filesPattern);
	reader.setResources(resources);
} catch (IOException e) {
	throw new IllegalArgumentException(
			"Unable to initialize resources by the pattern " + this.filesPattern, e);
}

However, I could not find a case that would actually trigger this block.
When no files are found for the specified pattern, PathMatchingResourcePatternResolver simply returns an empty Resource[] rather than throwing an exception.

I considered making the builder throw an exception when the resolved Resource[] has zero length, but decided it would be more appropriate to delegate such behavior to MultiResourceItemReader or its internal delegate. For example, FlatFileItemReader determines whether to throw an exception for missing files based on its strict property.

Resolves spring-projects#5056

Signed-off-by: Sanghyuk Jung <sanghyuk.jung@navercorp.com>
@benelog benelog changed the title Add support for file patterns in MultiResourceItemReaderBuilder Add support for multiple files via pattern in MultiResourceItemReaderBuilder Nov 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support specifying resource locations using a pattern in MultiResourceItemReaderBuilder

1 participant