spring batch遇到的一些问题

1.Spring Batch - A job instance already exists: JobInstanceAlreadyCompleteException

这是因为JobParameters 相同的任务只能成功运行一次 ,如果连续运行同一个job ,则会出现此异常,即launcher.run(job, new JobParameters())只能调用一次。

一个job由job的id和参数唯一确定,所以我们可以在参数中增加一个时间的参数,这样可以保证这个参数每次都会不同,从而可以多次调用,如下:

JobParametersBuilder builder = new JobParametersBuilder();
builder.addDate("date", new Date());
launcher.run(job, builder.toJobParameters());

这样就可以多次调用job了,参考链接:https://stackoverflow.com/questions/22455739/spring-batch-a-job-instance-already-exists-jobinstancealreadycompleteexceptio

http://blog.csdn.net/chenlei65368/article/details/8958770

原文地址:https://www.cnblogs.com/fxl-njfu/p/8022093.html