Spring Batch Partitioning inject stepExecutionContext parameter in itemReader

…衆ロ難τιáo~ 提交于 2019-12-06 03:13:50

Went through your code and tried to run it.

Currently it is not binding the file name at scope level.

You have two configuration files:

  1. SpringConfig - containing Spring related config beans
  2. SpringBatchConfig - containing Spring batch related beans

The first one contains the annotation @EnableBatchProcessing and @Configuration.

But the itemReader is defined in another config file which do not contain any of the annotations.

You should have @Configuration on the other file too.

OR

You can add both the annotations to SpringBatchConfig config file and can skip them in Spring

Without this, these configurations are not read properly and the itemReader is not considered as Step Scoped (i.e. the annotation @StepScope does not work) and does not bind the values at step level, and hence you are getting the NULL values.

Its not application code's responsibility to call partition method like you are doing in below ,

@Bean 
public TransactionPartitioner partitioner() {  
    TransactionPartitioner partitioner = new TransactionPartitioner();  
    partitioner.partition(10);  
    return partitioner;  
}  

Framework will call partition method for you. You simply need to return Partitioner without calling partition(10) method explicitly.

Having said that , you need to set partitioner gridSize in partitioner step as shown below,

@Bean 
public Step partitionStep() throws UnexpectedInputException, MalformedURLException, ParseException {  
    return steps.get("partitionStep").partitioner(step2()).partitioner("step2", partitioner()).gridSize(10).taskExecutor(taskExecutor).build();  
}  

Above points might be root cause for your issue. Rest of the things seem OK with your code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!