TechPrimers / spring-batch-example-1

Spring Boot with Spring Batch Example 1 (Load CSV to DB)
148 stars 231 forks source link

Error while running the source code #1

Open b4uazam opened 6 years ago

b4uazam commented 6 years ago

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.

sessam commented 5 years ago

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.

Okwori commented 5 years ago

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;
    }
surajarvind commented 2 years ago

what if i give the file from postman