我正在寻求帮助以找到在我的块侦听器中设置作业执行上下文的方法。
@Bean
public Step testStep(
JdbcCursorItemReader<TestStep> testStageDataReader,
TestStepProcessor testStepProcessor,
CompositeItemWriter<Writer> testWriter,
PlatformTransactionManager transactionManager,
JobRepository jobRepository, TestChunkListener testChunkListener) {
return stepBuilderFactory
.get("TESTING")
.<>chunk(100)
.reader(testStageDataReader)
.processor(testStepProcessor)
.writer(testWriter)
.faultTolerant()
.skip(DataIntegrityViolationException.class)
.skipLimit(4)
.listener(testSkipListener)
.transactionManager(transactionManager)
.repository(jobRepository)
.build();
}
跳过监听器
@Component
@RequiredArgsConstructor
@Slf4j
@StepScope
public class TestSkipListener {
private final TestRepository testRepository;
@Value("#{jobExecutionContext['jobExecutionTestId']}")
private Long jobExecutionTestId; //this is null
@OnSkipInWrite
public void onSkipInWrite(Writer writer,
Throwable t) {
logException(t);
}
}
我正在设置作业执行 ID
@Component
@Slf4j
@RequiredArgsConstructor
public class TestJobListener extends JobExecutionListenerSupport {
@Override
public void beforeJob(JobExecution jobExecution) {
long jobExecutionId = jobExecution.getJobId();
jobExecution.getExecutionContext()
.put("jobExecutionTestId", jobExecutionId);
}
}
这在我的处理器和编写器中工作正常,但在跳过侦听器时,它是空的