Pet*_*nto 2 spring-batch spring-batch-admin
我有一个 Spring Batch (2.2.2) 应用程序,由于某种原因无法使作业参数增量工作。该步骤声明如下:
<job id="job1" xmlns="http://www.springframework.org/schema/batch" incrementer="incrementer">
<step id="step1" parent="step" />
</job>
<bean id="incrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer" />
Run Code Online (Sandbox Code Playgroud)
当我将断点放入增量器时,它甚至没有被调用。
使用相同的参数两次调用作业会出现以下异常:
A job instance already exists and is complete for parameters={fail=false}. If you want to run this job again, change the parameters.
Run Code Online (Sandbox Code Playgroud)
我在这里检查了官方样品
https://github.com/spring-projects/spring-batch-admin/tree/master/spring-batch-admin-sample
它有同样的问题
小智 6
老问题,但仍适用于当前版本(3.0.5):
如果您通过以下方式开始作业执行
JobExecution jobExecution = launcher.run(job, jobParameters);
Run Code Online (Sandbox Code Playgroud)
使用例如SimpleJobLauncher
类,则永远不会调用增量器。如果检查方法的“调用者”,调用者Incrementer.getNext(JobParameters)
的数量是有限的:
CommandLineJobRunner在调用启动器之前getNext()
有条件地调用“-next” :
if (opts.contains("-next")) {
JobParameters nextParameters = getNextJobParameters(job);
Map<String, JobParameter> map = new HashMap<String, JobParameter>(nextParameters.getParameters());
map.putAll(jobParameters.getParameters());
jobParameters = new JobParameters(map);
}
JobExecution jobExecution = launcher.run(job, jobParameters);
Run Code Online (Sandbox Code Playgroud)
这是 Spring Admin Web 应用程序使用的,它与 CommandLineJobRunner 中的实现基本相同:
if (lastInstances.isEmpty()) {
parameters = incrementer.getNext(new JobParameters());
if (parameters == null) {
throw new JobParametersNotFoundException("No bootstrap parameters found for job=" + jobName);
}
}
else {
List<JobExecution> lastExecutions = jobExplorer.getJobExecutions(lastInstances.get(0));
parameters = incrementer.getNext(lastExecutions.get(0).getJobParameters());
}
logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters));
try {
return jobLauncher.run(job, parameters).getId();
}
catch (JobExecutionAlreadyRunningException e) {
throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job already running", jobName,
parameters), e);
}
Run Code Online (Sandbox Code Playgroud)
因此,如果您使用 JobLauncher 类来启动 Jobs,则在调用 jobLauncher 以使用您想要的值增强作业参数之前,必须注意调用增量器。
归档时间: |
|
查看次数: |
5610 次 |
最近记录: |