我有一个在使用分区策略的主/从之前运行的InitTasklet。在这个初始的tasklet中,我访问数据库并获得一个包含id的列表并放入上下文中:
chunkContext.getStepContext().getStepExecution().getJobExecution()
.getExecutionContext().put("listaBancos", lista);
我需要在我的分区程序中访问此列表
我尝试这种方式没有成功:从未执行beforeJob方法。
public class BancoPartitioner extends JobExecutionListenerSupport ...
@Override
public void beforeJob(JobExecution jobExecution) {
this.context = jobExecution.getExecutionContext();
super.beforeJob(jobExecution);
}
我尝试以这种方式自动执行stepExecution: @value( “#{stepExecution}”) private StepExecution stepExecution;
但我得到一个例外:
Error creating bean with name 'bancoPartitioner': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.StepExecution .....stepExecution; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'stepExecution' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'.
有没有办法从分区程序访问执行上下文?
答案 0 :(得分:4)
它在Partitioner Bean的声明中使用scope =“step”,正如bellabax所解释的那样。