gpt4 book ai didi

java - Spring 批处理 : JobExecution from PreparedStatementSetter

转载 作者:行者123 更新时间:2023-12-02 09:00:26 25 4
gpt4 key购买 nike

我有一个带有PreparedStatementSetter的Spring批处理,用于查询读取器步骤。我想从之前保存到 ExecutionContext 的PreparedStatementSetter 访问全局数据。

我如何从这个PreparedStatementSetter访问ExecutionContext?

@Component
public class CurrentBatchIdPreparedStatementSetter implements PreparedStatementSetter
{
@Override
public void setValues(PreparedStatement preparedStatement) throws SQLException
{
// how to access to ExecutionContext here ?
}
}

谢谢

是的,我们可以

最佳答案

如果范围是步骤,我们可以从步骤执行中获取 ExecutionContext。

    @Component
public class CurrentBatchIdPreparedStatementSetter implements PreparedStatementSetter
{
@Value("#{stepExecution}")
private StepExecution stepExecution;

@Override
public void setValues(PreparedStatement preparedStatement) throws SQLException
{
final ExecutionContext executionContext = stepExecution.getExecutionContext();
//Do your operations here
}
}

您还可以从作业执行上下文中获取相同的内容。

  @Value("#{jobExecution}")
private JobExecution jobExecution;
//inside method
final ExecutionContext executionContext = jobExecution.getExecutionContext();

或者您可以轻松地从作业执行上下文中获取值(value)。

        @Value ( "# {jobExecutionContext ['param1']}" ) 
private String param1;
@Value ( "# {jobExecutionContext ['param2']}" )
private String param2;

关于java - Spring 批处理 : JobExecution from PreparedStatementSetter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60211056/

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