我有一个带有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 ?
}
}
谢谢
是的我们可以
答案 0 :(得分:1)
如果范围是step,我们可以从步骤执行中获取ExecutionContext。
const merged = [...new Set([...obj1.nested.level1, ...obj2.nested.level1])]
您也可以从作业执行上下文中获得相同的信息。
@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();