I have a spring boot with spring batch application that is giving me below error:
8161 [01 Aug 2023 12:25:02.580] ERROR server01 [main] org.springframework.batch.core.step.AbstractStep - Encountered an error executing step step in job importUserJob
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.reader' defined in class path resource [com/batch/BatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.beanio.spring.BeanIOFlatFileItemReader]: Factory method 'reader' threw exception; nested exception is java.lang.IllegalArgumentException: Path must not be null
BatchConfiguration.java
@Bean
@StepScope
public BeanIOFlatFileItemReader<Contact> reader(@Value("#{jobParameters['filePath']}") String filePath) {
BeanIOFlatFileItemReader<Contact> reader = new BeanIOFlatFileItemReader<>();
reader.setUseSpringExceptions(true);
reader.setResource(new FileSystemResource(filePath));
reader.setStreamName(inputContactStreamName);
reader.setStreamMapping(new ClassPathResource(beanIoConfigurationXmlPath));
reader.setStreamFactory(StreamFactory.newInstance());
reader.getLineNumber();
return reader;
}
Any idea on why that error is coming and how to solve it?
This error means you are passing a null
filePath
here:
reader.setResource(new FileSystemResource(filePath));
Make sure the job parameter is correctly passed to the job.