How to resolve Input resource must exist (reader is in 'strict' mode) Spring Batch

698 views Asked by At

I'm reading a file from AWS S3 using resourceLoader.getResource in my Spring Batch application but I'm getting the below exception:

Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): class path resource [s3://myProduct/app/dev/product/input1]

I tried multiple solutions like using PathResource and other approaches but nothing worked out. Can someone please help me to resolve this issue? Please find my reader method below:

@Bean
@StepScope
public FlatFileItemReader<String> fileReader() {

    String bucketName = "myProduct";
    String key = "app/dev/product/input1";

    FlatFileItemReader reader = new FlatFileItemReader<>();
    reader.setResource(resourceLoader.getResource("s3://" +bucketName + "/" +key));
    reader.setLineMapper(new DefaultLineMapper());


    return reader;
}
1

There are 1 answers

1
yao Mr On

What is your resourceLoader? I assume it's spring's ResourceLoader, I guess it does not suit you. You can test other Resource, like UrlResource.