我有以下TicketProductPartitioner类和上下文。我已将bean范围设置为step并设置引用
<!-- Ticket partitioner into 15 steps -->
<bean id="ticketProductPartitioner" parent="abstractAttributionStep" class="a.b.c.batch.TicketProductPartitioner" scope="step">
<property name="stepExecution" value="#{stepExecution}"/>
</bean>
我的班级是
public class TicketProductPartitioner implements Partitioner {
private StepExecution stepExecution = null;
/**
* Create a ExecutionContext for each sub ticket of todays job
*/
public Map<String, ExecutionContext> partition(int gridSize) {
Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();
Date runDate = (Date) getStepExecution().getExecutionContext().get(AttributionParameter.RUN_DATE.name());
logger.info("Start TicketProductPartitioner job for run_date "+runDate);
但似乎stepExecution引用始终为null。如果这是一个简单的处理器bean,这种布线就可以工作,那么现在我在分区步骤中有什么不同呢?
答案 0 :(得分:1)
StepExecution不能使用spEL直接绑定,但必须注入,让TicketProductPartitioner
实现StepExecutionListener
标记带有@BeforeStep
注释的分区方法;这就是你的类字段为空的原因。