개발 기록
quartz job parameters processor에서 사용 본문
job
@Log4j2
@DisallowConcurrentExecution
@Component
public class TestJob extends QuartzJobBean {
@Autowired
private JobLauncher jobLauncher;
@Qualifier("TestJob")
@Autowired
private Job job;
@Override
protected void executeInternal(JobExecutionContext context) {
try {
log.info("[TestJob Job 실행]");
JobParameters jobParameter = new JobParametersBuilder()
.addString("type", "Test")
.toJobParameters();
jobLauncher.run(job, jobParameter);
} catch (JobInstanceAlreadyCompleteException | JobRestartException |
JobParametersInvalidException | JobExecutionAlreadyRunningException e) {
log.error(e);
}
}
}
spring batch
configuration
@Bean
@StepScope
public TargetItemProcessor processor(@Value("#{jobParameters['type']}") String type) {
return new TargetItemProcessor(type);
}
processor
@StepScope
public class TargetItemProcessor implements ItemProcessor<Map<String,Object>, Map<String,Object>> {
private static final Logger log = LoggerFactory.getLogger(TargetItemProcessor.class);
public TargetItemProcessor(String type) {
this.type = type;
}
@Value("#{jobParameters['myParameter']}")
private String type;
@Override
public Map<String,Object> process(final Map<String,Object> map) throws Exception {
log.info("type = {}", type);
return map;
}
}
https://stackoverflow.com/questions/73478318/access-job-parameter-in-custom-itemprocessor
Access Job Parameter in Custom ItemProcessor
I am implementing a custom ItemProcessor<I, O> in spring batch for processing data from a Rest api . I want access some values from jobParameter inside my ItemProcessor class . Any suggestion...
stackoverflow.com
'TIL' 카테고리의 다른 글
One or more listeners failed to start. (1) | 2024.03.15 |
---|---|
docker 컨테이너 ip 확인 (0) | 2024.03.15 |
mongoDB object 검색 (0) | 2024.02.14 |
Cannot change the ExecutorType when there is an existing transaction (0) | 2024.02.13 |
Table 'tableName_seq' doesn't exist, @Slf4j cannot find symbol (0) | 2023.02.17 |
Comments