yadav_1992
yadav_1992

Reputation: 53

Read files from multiple directories in spring batch

I need to read files from multiple directories and than process and store the data into DB. Currently i am using chunk multiple resource reader and it is working fine for 1 directory. But now i have to read files from multiple directories. How to do it using spring batch

Upvotes: 1

Views: 920

Answers (1)

Niraj Sonawane
Niraj Sonawane

Reputation: 11055

You can use MultiResourceItemReader along with Step Scope. using StepScop late binding you can inject file location

MultiResourceItemReader<> multiResourceItemReader = new MultiResourceItemReader<>();
    ClassLoader cLoader = this.getClass().getClassLoader();
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cLoader);
    resources = resolver.getResources("file:" + FileLocationAsVaribale);
    multiResourceItemReader.setResources(resources);
    multiResourceItemReader.setDelegate(yourReader());

Upvotes: 4

Related Questions