在Spring Batch

时间:2017-11-15 16:38:35

标签: spring spring-batch

我在Spring Batch工作。 使用

从CSV文件中读取
  

org.springframework.batch.item.file.FlatFileItemReader

并使用XML创建另一个文件并将此文件移动到另一个文件夹。一切都很好,但是当我尝试从文件夹中删除创建的XML文件时,我收到以下错误:

  

执行步骤:[removeTransferedFiles]   2017-11-15 17:05:03,305 [jobLauncherTaskExecutor-1] INFO org.springframework.batch.core.step.tasklet.TaskletStep(afterCompletion:342) - 在步骤执行数据已更新时提交失败。恢复旧版本。

     

2017-11-15 17:05:03,320 [jobLauncherTaskExecutor-1] ERROR org.springframework.batch.core.step.tasklet.TaskletStep(afterCompletion:351) - 回滚状态未知的交易

     

2017-11-15 17:05:03,320 [jobLauncherTaskExecutor-1] INFO org.springframework.batch.core.step.ThreadStepInterruptionPolicy(isInterrupted:59) - 通过StepExecution中断步骤

     

2017-11-15 17:05:03,320 [jobLauncherTaskExecutor-1] ERROR org.springframework.batch.core.step.AbstractStep(执行:222) - 遇到执行步骤的错误   org.springframework.batch.core.JobInterruptedException:检测到作业中断状态。       在org.springframework.batch.core.step.ThreadStepInterruptionPolicy.checkInterrupted(ThreadStepInterruptionPolicy.java:42)       在org.springframework.batch.core.step.tasklet.TaskletStep $ 2.doInChunkContext(TaskletStep.java:277)       在org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)       在org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)       在org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)       在org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)       在org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250)       在org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)       在org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)       在org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)       在org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)       在org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)       在org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)       在org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)       在org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:293)       在org.springframework.batch.core.launch.support.SimpleJobLauncher $ 1.run(SimpleJobLauncher.java:120)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

     

2017-11-15 17:05:03,320 [jobLauncherTaskExecutor-1] ERROR org.springframework.batch.core.step.AbstractStep(执行:259) - 遇到错误保存批处理元数据。此作业现在处于未知状态,不应重新启动。   org.springframework.dao.OptimisticLockingFailureException:尝试使用错误的版本(1)更新步骤执行id = 3,其中当前版本为2       在org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.updateStepExecution(JdbcStepExecutionDao.java:185)       在org.springframework.batch.core.repository.support.SimpleJobRepository.update(SimpleJobRepository.java:171)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       at java.lang.reflect.Method.invoke(Method.java:606)       在org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)       在org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)       at org.springframework.transaction.interceptor.TransactionInterceptor $ 1.proceedWithInvocation(TransactionInterceptor.java:96)       at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)       在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)       在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)       在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)       在com.sun.proxy。$ Proxy19.update(未知来源)       在org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:253)       在org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)       在org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)       在org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)       在org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)       在org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)       在org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)       在org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:293)       在org.springframework.batch.core.launch.support.SimpleJobLauncher $ 1.run(SimpleJobLauncher.java:120)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:745)

     

2017-11-15 17:05:03,336 [jobLauncherTaskExecutor-1] INFO org.springframework.batch.core.job.AbstractJob(执行:309) - 遇到中断执行作业:步骤请求终止:StepExecution:id = 3 ,version = 1,name = removeTransferedFiles,status = UNKNOWN,exitStatus = UNKNOWN,readCount = 0,filterCount = 0,writeCount = 0 readSkipCount = 0,writeSkipCount = 0,processSkipCount = 0,commitCount = 0,rollbackCount = 1,exitDescription = org.springframework.batch.core.JobInterruptedException

该文件实际上已从文件夹中删除,但该作业在此之后抛出此错误,并且永远不会获得COMPLETED状态或STOPPED状态。

我的job.xml(或部分内容)                                                                                                                                                                                                                                    

<job id="CSVJob" xmlns="http://www.springframework.org/schema/batch" incrementer="jobParamsIncrementer">
    <validator ref="validator" />
    <step id="writeCSVFile" next="transferToFolder" parent="chunkStep">
        <tasklet>
            <chunk reader="CSVReader" writer="XMLWriter"
                   processor="CSVProcessor" />
        </tasklet>
    </step>
    <step id="transferToFolder" next="removeTransferedFiles">
        <tasklet ref="fileTransferTasklet">
            <transaction-attributes propagation="NEVER" />                
        </tasklet>
    </step>
    <step id="removeTransferedFiles">  
        <tasklet ref="removeFileTasklet">
        </tasklet>
    </step>        
</job>

我在Spring Batch中使用相同的FlatFileItemReader进行其他工作,但我没有遇到相同的错误。 我使用在我们的批处理通用模块中编写的removeFileTasklet,该类在其他作业中工作,在从其文件夹中删除文件后抛出此错误。

为什么会出现此错误?我理解步骤执行的版本是错误的,但是它为什么以及在哪里更新了版本以及如何防止它这样做?

我不确定你们需要多少才能回答我的问题所以请告诉我你是否需要更多信息。 谢谢你的时间。

0 个答案:

没有答案