有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java SpringBatch命令行JobRunner下一步使用旧运行。身份证件

我们使用CommandLineJobRunner执行Spring批处理作业。我们正在命令行中使用-next:

java -Dlog4j.configuration=file:./prop/log4j.properties -Dlogfile=logfile_load_data -jar EtlLoadData.jar loaddata_etl_config.xml loaddata_etl_job -next

我们开始遇到一个错误:

Job Terminated in error: A job instance already exists and is complete for parameters={run.id=10}.  If you want to run this job again, change the parameters. 

org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={run.id=10}.  If you want to run this job again, change the parameters.
    at  org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:122)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:168)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy14.createJobExecution(Unknown Source)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:111)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574)

我认为如果您使用-next选项运行,这应该不是问题。有什么想法吗

作为临时解决办法,我清理了数据库中的SpringBatch表,但我不希望这种情况再次发生


共 (2) 个答案

  1. # 1 楼答案

    不知道下一个选项

    最快的方法是将当前时间戳作为参数传递给作业。这样它将是独一无二的,不会真正干扰你的工作

  2. # 2 楼答案

    使用de-next选项,您应该设置JobParametersIncrementer实现

    在本例中,我使用->;新建RunIdIncrementer以避免出现以下消息:作业实例已存在,并且参数已完成

    @Autowired
    private JobBuilderFactory jobs;
    ...
    @Bean(name=JOB_NAME)
    public Job job() {        
    
        return jobs.get(JOB_NAME)
                   .start(this.login())
                   .next(this.launchDuke())
                   .incrementer(new RunIdIncrementer())
                   .build();
    }