问题描述
我想在我的 ItemWriter
类中检索 JobParameter
和 JobExecutionContext
对象.如何进行?
I want to retrieve JobParameter
and JobExecutionContext
object in my ItemWriter
class.How to proceed?
我尝试实现 StepExecutionListener
,通过该方法我只是调用父类方法.但这并不成功.
I tried implementing StepExecutionListener
through which I am just calling the parent class methods. But it is not succeeding.
谢谢.
推荐答案
实现StepExecutionListener是一种方法.实际上,这是Spring Batch 1.x的唯一方法.
Implementing StepExecutionListener is one way. In fact that's the only way in Spring Batch 1.x.
从Spring Batch 2开始,您还有另一种选择:您可以将Job Parameters和Job Execution Context中的任何条目注入到项目编写器中.使您的项目作者具有 step
范围,然后使用诸如#{jobParameters ['theKeyYouWant']}
或#{jobExecutionContext ['someOtherKey']}之类的表达式
为您的项目编写者注入价值.
Starting from Spring Batch 2, you have another choice: You can inject whatever entries in Job Parameters and Job Execution Context to your item writer. Make your item writer with step
scope, then make use of expression like #{jobParameters['theKeyYouWant']}
or #{jobExecutionContext['someOtherKey']}
for value injecting to you item writer.
这篇关于如何在ItemWriter中获取JobParameter和JobExecutionContext?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!