java - 如何在 Spring 批处理的作业上下文 xml 文件中使用 jobExecution

我正在研究 spring Batch。我在 JobListener beforeStep 方法中将作业执行上下文中的一些参数设置为键值对。我想在我的 bean 定义中检索这些参数。但是我遇到了异常。

我在作业定义中配置了这个监听器。

我的 beforeJob() 方法就像..

public void beforeJob(JobExecution jobExecution) {
    // TODO Auto-generated method stub
    System.out.println("Before Member Number Import Job");
    log.info("Writing Failed File Header");
    jobExecution.getExecutionContext().put("date", DateUtil.getDateString());
    jobExecution.getExecutionContext().put("fileName", "dummy.txt");
    writeHeader();
}

我用它来设置 FlatFileReader bean 的资源属性。

<property name="resource" value="file:#{jobExecutionContext['date']}" />

我遇到以下异常。

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'jobExecutionContext' 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.CompoundExpression.getValueInternal(CompoundExpression.java:52)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:97)
at org.springframework.expression.common.CompositeStringExpression.getValue(CompositeStringExpression.java:82)
at org.springframework.expression.common.CompositeStringExpression.getValue(CompositeStringExpression.java:1)
at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:139)
... 27 more

请建议我如何解决这个问题。 提前致谢

最佳答案

正如他们在评论中所说,这是解决添加 scope="step"

<bean id=".." class="..." scope="step">
    <property name=".." value="#{jobExecutionContext[..']}"/>
</bean>

关于java - 如何在 Spring 批处理的作业上下文 xml 文件中使用 jobExecutionContext ['key' ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31539898/

相关文章:

facebook - Graph Facebook 发生未知错误

r - 如何计算 vowpal wabbit 中 LDA 模型的对数似然

javascript - 使用 python 电子邮件或其他模块在电子邮件中发送 Bokeh 图

wpf - 右键单击 + 左键单击被视为拖放

sql - 如何在 SQL MS Access 2013 中根据文本特征标准和 n+1、n+2、n+

php - 带有 PHP SDK 的 AWS EC2 - 等到实例具有公共(public) DNS

android - AlertDialog 内的 DatePickerDialog(在特定的 Edi

cmake - 带有特殊字符的 custom_command ECHO

asp.net - executionTimeout 发送响应

java - 如何通过键前缀查询 Samza KeyValueStore?