如何在Spring Batch中发送自定义对象作为Job参数? [英] how to send a custom object as Job Parameter in Spring Batch?

查看:446
本文介绍了如何在Spring Batch中发送自定义对象作为Job参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向Spring Batch Job发送一个自定义对象,其中该对象被项目处理器连续用于业务需求.

I have a requirement of sending a Custom Object to the Spring Batch Job , where this Object is used continuously used by the Item Processor for the business requirement.

我们如何将自定义对象从外部发送到作业上下文.此对象随作业而变化,并在运行时根据业务情况生成.

How can we send custom object from outside to the Job Context. This Object changes from Job to Job and generated at runtime depending on Business case.

如何将其作为作业参数发送?还是有什么办法可以将此对象设置为相应的Job?

How can send this as a Job Parameter? or is there any way that i can set this Object to the respective Job ?

重载Spring JobParameter可以以任何方式帮助我吗?还是这种压倒性行为会导致任何大问题?

can overriding Spring JobParameter help me in any way? or are there any Big issues as an outcome of this Overriding behaviour ?

推荐答案

在此JobParameter发送的原因. -无法投射到组织springframework-batch-core-jobparameter/31625130#31625130>问题.关于该问题,您有几种想法.

I have summarized reasons why you cannot send object as JobParameter in this question. There are couple of ideas on that question how you can do it.

TL:TR:我认为最好的方法是在数据库中创建表,该表存储对象并将该记录的ID作为JobParameter传递,或者将Object序列化为json并将其作为String传递给Job作为JobParameter.如果选择第二种方法,请注意string_val以varchar 250的形式存储在数据库中,因此限制为250个字符.

TL:TR: I think best way would be either to create table in DB which stores Object and pass id of that record as JobParameter or to serialize Object to json and pass it as String in job as JobParameter. If you go with second option be aware that string_val is stored in DB as varchar 250 so limit is 250 characters.

这篇关于如何在Spring Batch中发送自定义对象作为Job参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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