gpt4 book ai didi

java - Spring Batch : How to pass data from StepExecution to JobExecution without persisting it (that is, 不使用 ExecutionContext)?

转载 作者:太空宇宙 更新时间:2023-11-04 14:59:13 26 4
gpt4 key购买 nike

我有一个 JobExecutionListener.afterJob() 实现,它打印从所有先前步骤执行中获得的一些信息:

JobExecutionListener.beforeJob():

jobExecution.getExecutionContext().putString("key", "");

步骤1:StepExecutionListener.beforeStep():

ExecutionContext context = stepExecution.getJobExecution().getExecutionContext();
context.putString("key", context.getString("key") + "Hello");

步骤2:StepExecutionListener.beforeStep():

ExecutionContext context = stepExecution.getJobExecution().getExecutionContext();
context.putString("key", context.getString("key") + " World!");

JobExecutionListener.afterJob():

System.out.println(jobExecution.getExecutionContext().getString("key"));
// results in "Hello World!"

但是当执行这样的作业时,这些数据将被持久化(例如,在BATCH_JOB_EXECUTION_CONTEXT表中)。如何避免这种情况?

最佳答案

使用外部 bean 保存要在步骤之间传递的数据;此外部 bean 未持久保存,您需要连接到 SB 工件或监听器。

关于java - Spring Batch : How to pass data from StepExecution to JobExecution without persisting it (that is, 不使用 ExecutionContext)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22810776/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com