spring-batch-example-1 icon indicating copy to clipboard operation
spring-batch-example-1 copied to clipboard

Error while running the source code

Open b4uazam opened this issue 6 years ago • 3 comments

Hi TechPrimers, Thanks for your code share, I have couple of queries, answering my queries will be appreciated.

  1. We noticed the error as below with given code base, Please take a look: Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [file:/Users/apple/Downloads/spring-batch-example-1/src/main/resources/users.csv] at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:251) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE] at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:144) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]... 76 common frames omitted

2.Currently I am running this application by hardcording the resource input, and its runnign as expected, But how can I run this application to pick the source file((~5 millions records) from shared drive location, instead of pickign from resource folder, What changes are required for it?

3.What are the changes required to switch it to other data sources(sql server). ? Please suggest the code changes, thanks in advance.

b4uazam avatar Sep 01 '18 22:09 b4uazam

Hi TechPrimers, Thanks for your code share, I have couple of queries, answering my queries will be appreciated.

  1. We noticed the error as below with given code base, Please take a look: Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [file:/Users/apple/Downloads/spring-batch-example-1/src/main/resources/users.csv] at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:251) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE] at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:144) ~[spring-batch-infrastructure-3.0.9.RELEASE.jar:3.0.9.RELEASE]... 76 common frames omitted PS: Hope you changed the file path in application.properties (I resolved this by adding mine) 2.Currently I am running this application by hardcording the resource input, and its runnign as expected, But how can I run this application to pick the source file((~5 millions records) from shared drive location, instead of pickign from resource folder, What changes are required for it?

3.What are the changes required to switch it to other data sources(sql server). ? Please suggest the code changes, thanks in advance.

sessam avatar Dec 03 '18 18:12 sessam

You can replace this method in SpringBatchConfig.java

@Bean
    public FlatFileItemReader<User> itemReader() {
        FlatFileItemReader<User> flatFileItemReader = new FlatFileItemReader<>();
        flatFileItemReader.setResource(new ClassPathResource("users.csv"));
        flatFileItemReader.setName("CSV-Reader");
        flatFileItemReader.setLinesToSkip(1);
        flatFileItemReader.setLineMapper(lineMapper());
        return flatFileItemReader;
    }

Okwori avatar Jun 10 '19 06:06 Okwori

what if i give the file from postman

surajarvind avatar Oct 14 '22 11:10 surajarvind