如何注入ExecutionContext或格式属性,并使用SpringBatch在My FieldExtractor上使用它

时间:2014-07-17 20:14:54

标签: batch-processing spring-batch

我必须为我的工作实现一个自定义的FieldExtractor,如:

public class MyFieldExtractor implements
    FieldExtractor<MyEntity> {

    @Override
    public Object[] extract(MyEntity e) {
           ......
    }
}

在我的xml中,我在自定义的Line Aggregator中使用它,例如: &#34;格式&#34;属性是动态绑定的。

<bean id="myLineAggregator"
    class="org.springframework.batch.item.file.transform.FormatterLineAggregator" scope="step">
    <property name="fieldExtractor">
        <bean
            class=".........MyFieldExtractor">
        </bean>
    </property>
    <property name="format" value="1$01d%#{jobExecutionContext[$jc{filename}].dynamicFormat}"/>
</bean> 

I need a way to inject or to get the "format" property in my class MyFieldExtractor or at least, I would to inject the ExecutionContext in some field. 

我试过了:

@Value("#{jobExecutionContext[]}")
private ExecutionContext context;

@Value("#{jobExecutionContext}")
private ExecutionContext context;

...不成功

有可能吗?

1 个答案:

答案 0 :(得分:0)

JobExecution s(以及StepExecution s)无法直接绑定,因此@Value("#{jobExecutionContext}")无法正常工作。
您可以使用1$01d%#{jobExecutionContext[$jc{filename}].dynamicFormat}注释注入#{jobExecutionContext[$jc{filename}]}@Value()