How do I get Spring Batch Job ContextId in ItemProcessor or ItemWriter?

后端 未结 6 2366
说谎
说谎 2021-02-20 18:12

I need to store Job ExecutionId as one of the fields of Entity. (I am using JpaItemWriter) One of topic here explains from StepExcecution, I can get StepContext -> JobExecution.

6条回答
  •  遇见更好的自我
    2021-02-20 18:28

    We can set the scope as job using @Scope("job") of Itemprocessor and can easly get JobExecution using @Value("#{jobExecution}") expression as below.

    @Service
    @Scope("job")
    public class XsltTransformer implements ItemProcessor {
    
    @Value("#{jobExecution}")
    private JobExecution jobExecution;
    
    }
    

提交回复
热议问题