【问题标题】:Spring batch reader complain about resourceSpring批处理阅读器抱怨资源
【发布时间】:2018-10-05 09:43:30
【问题描述】:

当我尝试启动 Spring Boot 应用程序时出现以下错误。它甚至在我提供我的工作参数之前就给出了一个错误,这是我的工作的一个参数。

很多讨论建议使用资源作为file:#{jobParameters[controlFileInput]} 来解决这个问题。但这对我不起作用。提前致谢。

批处理 xml

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/batch
    http://www.springframework.org/schema/batch/spring-batch-3.0.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util-4.2.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.2.xsd">

    <context:property-placeholder location="classpath:application.properties" />
    <bean id="stepScope" class="org.springframework.batch.core.scope.StepScope">
        <property name="autoProxy" value="true" />
    </bean>
    <bean id="billItemWriteListener"
        class="com.telstra.billubfreader.listener.BillItemWriteListener" />
    <bean id="billItemProcessListener"
        class="com.telstra.billubfreader.listener.BillItemProcessListener" />

    <bean id="fileMovingToErrorTasklet"class="com.telstra.billubfreader.ErrorFileMover" />
    <bean id="fileMovingToSuccessTasklet"
        class="com.telstra.billubfreader.SuccessFileMover" />

    <bean id="billControlFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader"
        scope="step">
        <property name="resource" value="file:#{jobParameters[controlFileInput]}" />
        <property name="linesToSkip" value="${control.linetoskip}" />
        <property name="lineMapper">
            <bean class="com.telstra.billubfreader.mapper.BillControlLineMapper">
                <property name="lineTokenizer">
                    <bean   class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                    </bean>
                </property>
                <property name="fieldSetMapper">
                    <bean
                        class="com.telstra.billubfreader.mapper.BillControlFieldDataMapper" />
                </property>
            </bean>
        </property>
    </bean>
    <bean id="billControlItemProcessor" class="com.telstra.billubfreader.BillControlItemProcessor"
        scope="step">
    </bean>
    <bean id="billControFileItemwriter" class="com.telstra.billubfreader.BillControlItemWriter"
        scope="step">
    </bean>


    <batch:job id="billControlFileReaderJob" restartable="true">
        <batch:step id="billControlFileRaderStep1">
            <batch:tasklet>
                <batch:chunk reader="billControlFileItemReader"
                    processor="billControlItemProcessor" writer="billControFileItemwriter"
                    commit-interval="25">
                    <batch:listeners>
                        <batch:listener ref="billItemWriteListener" />
                        <batch:listener ref="billItemProcessListener" />
                        <batch:listener ref="promotionListener"/>

                    </batch:listeners>
                </batch:chunk>
            </batch:tasklet>
             <batch:next on="FAILED" to="fileMovingtoError" />
              <batch:next on="COMPLETED" to="fileMovingToSuccess" />
        </batch:step>
        <batch:step id="fileMovingtoError">
        <tasklet ref="fileMovingToErrorTasklet"/>
        </batch:step>
        <batch:step id="fileMovingToSuccess">
        <tasklet ref="fileMovingToSuccessTasklet"/>
        </batch:step>
    </batch:job>
    <bean id="promotionListener"
class="org.springframework.batch.core.listener.ExecutionContextPromotionListener">
    <property name="keys" value="filesToMove"/>
</bean>

</beans>

日志

2018-04-25 12:10:05.779 INFO 22716 --- [main] osbatch.core.job.SimpleStepHandler :步骤已完成或不可重新启动,因此无需执行任何操作:StepExecution:id=1,版本=15,名称=billControlFileRaderStep1,状态=ABANDONED,exitStatus=FAILED,readCount=0,filterCount=0,writeCount=0 readSkipCount=0,writeSkipCount=0,processSkipCount=0,commitCount=0,rollbackCount=0,exitDescription=org。 springframework.batch.item.ItemStreamException:初始化阅读器失败 在 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:149) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源) 在 java.lang.reflect.Method.invoke(未知来源) 在 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) 在 org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136) 在 org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) 在 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) 在 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) 在 com.sun.proxy.$Proxy52.open(未知来源) 在 org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103) 在 org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310) 在 org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197) 在 org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) 在 org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:66) 在 org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) 在 org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) 在 org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) 在 org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136) 在 org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:308) 在 org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:141) 在 org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) 在 org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:134 2018-04-25 12:10:06.201 INFO 22716 --- [main] osbatch.core.job.SimpleStepHandler :步骤已经完成或不可重新启动,因此无需执行任何操作:StepExecution:id=2,版本=3, name=fileMovingtoError, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2018-04-25 12:10:06.334 INFO 22716 --- [main] o.s.b.c.l.support.SimpleJobLauncher:作业:[FlowJob:[name=billControlFileReaderJob]] 完成

【问题讨论】:

  • 我想这个错误与resource 设置无关。也许Step already complete or not restartable, so no action to execute 是主要原因。所以你可以尝试在每次开始工作之前给不同的jobParamters,就像JobParameters jobParameters = new JobParametersBuilder().addDate("date", new Date()) .toJobParameters(); 一样。
  • @weaver 我也在用日期运行它..但没有运气..这个错误甚至在我执行作业之前就出现了

标签: spring spring-batch


【解决方案1】:

我在这里发现了问题。问题是SpringApplication.run 在我启动作业之前执行作业。所以,它没有工作参数。设置 spring.batch.job.enabled=false 解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-11
    • 1970-01-01
    相关资源
    最近更新 更多