简体   繁体   中英

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

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;
}

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM