Spring批处理读者抱怨资源

时间:2018-04-25 02:54:28

标签: spring spring-batch

当我尝试启动Spring启动应用程序时,我遇到了以下错误。即使在我提供作业参数之前,它也会出错。

很多讨论建议使用资源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,version = 15,name = billControlFileRaderStep1,status = 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)           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)           at java.lang.reflect.Method.invoke(Unknown Source)           在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,version = 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:Job:[FlowJob:[name = billControlFileReaderJob]] complet

1 个答案:

答案 0 :(得分:0)

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