我正在尝试使用Spring批处理批处理作业。
当我尝试使用stop
executionId
正在运行的作业时,作业将在SpringBatchDb.BATCH_JOB_EXECUTION
表
' 104',' 3',' 104',' 2017-11-27 11:39:10',&# 39; 2017-11-27 11:39:10',2017-11-27 11:39:48','停止'停止'停止'停止;,' org.springframework.batch.core.JobInterruptedException',' 2017-11-27 11:39:48',NULL
请注意,STATUS
和EXIT_CODE
更新为STOPPED
。但它引发了一个例外,org.springframework.batch.core.launch.NoSuchJobException: No job configuration with the name [testJob] was registered
at org.springframework.batch.core.configuration.support.MapJobRegistry.getJob(MapJobRegistry.java:66)
at org.springframework.batch.core.launch.support.SimpleJobOperator.restart(SimpleJobOperator.java:275)
at org.springframework.batch.core.launch.support.SimpleJobOperator$$FastClassBySpringCGLIB$$44ee6049.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:669)
at org.springframework.batch.core.launch.support.SimpleJobOperator$$EnhancerBySpringCGLIB$$318ff269.restart(<generated>)
at com.test.mypackage.batch.dao.BatchJobDaoImpl.restartJobExecution(BatchJobDaoImpl.java:62)
。
当我尝试使用executionId重新启动相同的作业时,它无法启动并提供相同的异常(如上所示)。
我的代码很简单,
@Autowired
private DataSource dataSource;
@Autowired
private JobOperator jobOperator;
@Override
public Long stopRunningExecution(Long executionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException {
jobOperator.stop(executionId);
return executionId;
}
@Override
public Long restartJobExecution(long executionId) throws JobParametersInvalidException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException {
return jobOperator.restart(executionId);
}
这里有什么问题?
答案 0 :(得分:2)
我遇到了类似的错误但是能够解决问题。
由于您尚未定义JobRegistry,因此问题正在发生。如果您定义JobRegistry并将其添加到JobOperator Bean,则不会发生上述异常。
例如:
@Bean
public JobRegistry jobRegistry() {
return new MapJobRegistry();
}
@Bean
public JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor() {
JobRegistryBeanPostProcessor jobRegistryBeanPostProcessor = new JobRegistryBeanPostProcessor();
jobRegistryBeanPostProcessor.setJobRegistry(jobRegistry());
return jobRegistryBeanPostProcessor;
}
@Bean
public JobOperator jobOperator() {
SimpleJobOperator jobOperator = new SimpleJobOperator();
jobOperator.setJobExplorer(getJobExplorer());
jobOperator.setJobRepository(getJobRepository());
jobOperator.setJobLauncher(getJobLauncher());
jobOperator.setJobRegistry(jobRegistry());
return jobOperator;
}