Spring Batch : Field or property 'stepExecutionContext' cannot be found

谁说我不能喝 提交于 2019-12-02 19:43:45

问题


I have the following spring batch job configuration. There is a single reader which then passes details to a composite writer which has two specific writers. Both writers share a common parent and need to use the same JobId for the INSERT operations they execute.

<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"/>

When i run my code i get the following error

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)

I have tried setting the scope="step" in various place but to no avail. Any suggestions?


回答1:


You can access the stepExecutionContext only within a bean defined in the scope="step". Change your bean definition to

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

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


来源:https://stackoverflow.com/questions/21112446/spring-batch-field-or-property-stepexecutioncontext-cannot-be-found

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