英文:
Getting batch job id nside ItemProcessListener in spring batch 5
问题
I want to display batch job id in my logs on err. Any idea? ty.
英文:
My listener is as given below :
@Component
@Slf4j
public class ProcessorExecutionListener implements ItemProcessListener<OriginDAO, DestinationDAO> {
@Override
public void onProcessError(OriginDAO originADAO, Exception e) {
log.error("Want to display batch job id here in the logs. Is it possible?");
}
}
I want to display batch job id in my logs on err. Any idea? ty.
答案1
得分: 0
以下是要翻译的代码部分:
@Component
@StepScope
@Slf4j
public class ProcessorExecutionListener implements ItemProcessListener<OriginDAO, DestinationDAO> {
@Value("#{stepExecution}")
private StepExecution stepExecution;
@Override
public void onProcessError(OriginDAO item, Exception e) {
Long jobId = stepExecution.getJobExecution().getJobId();
log.error("batch job id = {}", jobId);
}
}
This listener should be registered in the step as a listener as well.
英文:
You can do that by making the listener step-scoped and inject the step execution in it. Here is an example:
@Component
@StepScope
@Slf4j
public class ProcessorExecutionListener implements ItemProcessListener< OriginDAO, DestinationDAO> {
@Value("#{stepExecution}")
private StepExecution stepExecution;
@Override
public void onProcessError(OriginDAO item, Exception e) {
Long jobId = stepExecution.getJobExecution().getJobId();
log.error("batch job id = {}", jobId);
}
}
This listener should be registered in the step as a listener as well.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论