我很好奇是否有可能通过除方法之外的其他方式定义Spring Batch Job。有什么方法可以通过创建一个扩展Job的@Component并使用注入的JobBuilderFactory来创建实例来定义批处理作业,从而避免自己实施所有必需的方法?
@Component
public class ImportEmployeeJob extends FlowJob {
private final JobBuilderFactory jobBuilderFactory;
private final FlowStep printProcessedEmployeeFromCsv;
public ImportEmployeeJob(JobBuilderFactory jobBuilderFactory, FlowStep printProcessedEmployeeFromCsv, ApplicationContext context) {
this.jobBuilderFactory = jobBuilderFactory;
this.printProcessedEmployeeFromCsv = printProcessedEmployeeFromCsv;
jobBuilderFactory.get("importEmployeeJob")
.incrementer(new RunIdIncrementer())
.listener(new PersonCsvJobExecutionListener())
.flow(printProcessedEmployeeFromCsv)
.end()
.build();
}
}
这是个愚蠢的例子,但我只想告诉你我的意思
答案 0 :(得分:0)
您可以为此使用工厂bean。这是一个简单的示例:
Background activity start from package-name blocked.
希望有帮助。