I'm writing a batch using Spring Batch and am trying to pass a job parameter to the item reader bean definition, but when I'm executing the batch I keep getting the following error:
org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos 13): Indexing into type 'org.springframework.batch.core.JobParameters' is not supported
Here is the code of the configuration class:
/**
* Job producing an XML file aimed at synchronizing Appipay data with ForHRM data
*
* @author francois.dupire
*/
@Configuration
@Import(BatchConfiguration.class)
@ComponentScan(basePackageClasses = BusinessObjectServiceImpl.class)
public class ForHRMToAppipayDescriptiveDataSyncJobConfiguration {
/*
* Constants
*/
public static final String JOB_NAME = "forHRMToAppipaySyncJob";
private static final String FORHRM_TO_APPIPAY_SYNC_STEP = "forHRMToAppipaySyncStep";
private static final int CHUNK_SIZE = 10;
/*
* Fields
*/
private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
/*
* Constructors
*/
@Autowired
public ForHRMToAppipayDescriptiveDataSyncJobConfiguration(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
this.jobBuilderFactory = jobBuilderFactory;
this.stepBuilderFactory = stepBuilderFactory;
}
/*
* Job
*/
@Bean
public Job forHRMToAppipaySyncJob(Step forHRMToAppipaySyncStep) {
return jobBuilderFactory
.get(JOB_NAME)
.start(forHRMToAppipaySyncStep)
.build();
// TODO Add parameters validator
}
/*
* Steps
*/
// Sync step
@Bean
public Step forHRMToAppipaySyncStep(AppipaySyncTriggersReader reader, AppipaySyncTriggersToAppipayDescriptiveDataProcessor processor, AppipayDescriptiveDataWriter writer) {
return stepBuilderFactory
.get(FORHRM_TO_APPIPAY_SYNC_STEP)
.<List<SynchronisationAppipay>, Signaletiques>chunk(CHUNK_SIZE)
.reader(reader)
.processor(processor)
.writer(writer)
.build();
}
@Bean
@StepScope
public AppipaySyncTriggersReader appipaySyncTriggersReader(@Value("#{jobParameters['EMPCODE']}") String employerCode, SynchronisationAppipayRepository appipaySyncTriggerRepository) {
return new AppipaySyncTriggersReader(employerCode, CHUNK_SIZE, appipaySyncTriggerRepository);
}
I tried the following solutions:
- Use jobExecutionContext and stepExecutionContext instead of jobParameters. As a result I got null objects instead of passed parameters;
Remove simple quote from around parameters name (e.g. #jobParameters[EMPCODE]), but then I got this error:
Invalid property 'EMPCODE' of bean class [org.springframework.batch.core.scope.context.StepContext]: Bean property 'EMPCODE' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
I just don't know what I'm doing wrong because everything seems okay according to documentation and other posts I found browsing the net.
EDIT : I'm using Spring 4.3.3 and Spring Batch 3.0.7