春批:找不到字段或属性'stepExecutionContext' [英] Spring Batch : Field or property 'stepExecutionContext' cannot be found

查看:22
本文介绍了春批:找不到字段或属性'stepExecutionContext'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Spring批处理作业配置。有一个单一的读取器,然后将细节传递给具有两个特定写入器的复合写入器。两个编写器共享共同的父级,并且需要对它们执行的插入操作使用相同的JobId。

<bean id="job" parent="simpleJob">
    <property name="steps">
        <list>
            <bean parent="simpleStep">
                <property name="itemReader" ref="policyReader"/>    
                <property name="itemWriter" ref="stagingCompositeWriter"/>
            </bean>
        </list>
    </property>
</bean>

<bean id="stagingCompositeWriter" class="org.springframework.batch.item.support.CompositeItemWriter">
    <property name="delegates">
        <list>
            <ref bean="stagingLoadWriter"/>
            <ref bean="stagingPolicyWriter"/>
        </list>
    </property>
</bean>

<bean id="abstractStagingWriter" class="a.b.c.AbstractStagingWriter" abstract="true">
    <property name="stepExecution" value="#{stepExecutionContext}"/>
    <property name="hedgingStagingDataSource" ref="hedgingStagingDataSource"/>
</bean>

<bean id="stagingLoadWriter" class="a.b.c.StagingLoadWriter" parent="abstractStagingWriter"/>

<bean id="stagingPolicyWriter" class="a.b.c.StagingPolicyWriter" parent="abstractStagingWriter"/>

运行代码时出现以下错误

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'stepExecutionContext' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext'
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:208)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:72)
at org.springframework.expression.spel.ast.SpelNodeImpl.getValue(SpelNodeImpl.java:93)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:88)
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:139)

我已经尝试在各个地方设置scope="step",但都无济于事。有什么建议吗?

推荐答案

您只能在Scope="Step"中定义的Bean内访问stepExecutionContext。 将Bean定义更改为

<bean id="stagingLoadWriter" scope="step" class="a.b.c.StagingLoadWriter" parent="abstractStagingWriter" />

<bean id="stagingPolicyWriter" scope="step" class="a.b.c.StagingPolicyWriter" parent="abstractStagingWriter"/>

这篇关于春批:找不到字段或属性&#39;stepExecutionContext&#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆