Reputation: 1179
I am facing an issue. When I am moving FlatFileItemReader and Step into separate configuration file it stopped working.
The actual issue is it is not able to get the jobParameters.
@Configuration
public class FileReader {
@Bean("personFileReader")
@StepScope
public FlatFileItemReader<Person> personFileReader(@Value("#(jobParameters['customerFile']") FileSystemResource fileName) {
System.out.println(
String.format("fileName = %s", fileName));
return new FlatFileItemReaderBuilder<Person>().name("personItemReader").resource(fileName).fixedLength()
.columns(getRange()).names(getNames()).targetType(Person.class).build();
}
Batch Config
@Configuration
@EnableBatchProcessing
public class BatchConfiguration extends DefaultBatchConfigurer {
@Autowired
@Qualifier("personFileReader")
private FlatFileItemReader<Person> personFileReader;
@Bean
public Step step() {
return this.stepBuilderFactory.get("chunkStep").<Person, Person>chunk(10).reader(personFileReader)
.writer(dummyWriter).build();
}
Error
Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): file [D:\Data\Study\spring-batch\batch-process\#(jobParameters['customerFile']]
I have no idea what wrong I am doing.
Upvotes: 0
Views: 250
Reputation: 36173
The @Value annotation seems to be incorrect
@Value("#(jobParameters['customerFile']")
Should be
@Value("#{jobParameters['customerFile']}")
Upvotes: 1