Spring Batch:如何将jobParameters传递给自定义bean? [英] Spring Batch: how to pass jobParameters to a custom bean?

查看:29
本文介绍了Spring Batch:如何将jobParameters传递给自定义bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在研究Spring Batch,遇到了一个需要将jobParameter传递给自定义bean的场景。作业参数包含文件的路径。

以下是我的上下文的外观:

<bean id="myBean" class=".....MyBean">
     <property name="path" value="file:#{jobParameters['PATH'}/fileName"/>
</bean>

这已包含在此处未包含的读取器的步骤作用域中。

问题是。实例化该类时,传递给Bean的值为 "file:#{jobParameters[‘path’}/filename",而不是在调用作业时传递jobParameter的值。这让我感到困惑,因为我在multiResourceReader上尝试了它来设置资源值,并且它工作得很好。我只是不能让它在定制的豆子上工作。如有任何帮助,我们将不胜感激。

推荐答案

您需要在Bean定义中使用Scope="Step"。

<bean id="myBean" class=".....MyBean" scope="step">
    <property name="path" value="file:#{jobParameters['PATH']}/fileName"/>
</bean>

另外,您的#{jobParameters[‘path’}缺少右括号]

这篇关于Spring Batch:如何将jobParameters传递给自定义bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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