Spring-Batch第二步不能正常工作

我正在配置一个有两步的作业,两个步骤都需要读取不同的文件并将数据转储到数据库 . 当我启动作业时,它执行第一步并成功保存数据,第二步不是读取文件 . 但是在数据库中我可以看到两个Step Status都成功了 . 我的配置如下所示:

job id="job1" job-repository="jobRepository" xmlns="http://www.springframework.org/schema/batch" restartable="true">
    <step id="step1">
        <tasklet transaction-manager="transactionManager" task-executor="taskExecutor">
            <chunk reader="DomainItemReader" writer="DomainItemWriter" commit-interval="40" skip-limit="10">
                <skippable-exception-classes>
                    <include class="java.lang.Exception"/>
                    <exclude class="java.io.FileNotFoundException"/>
                </skippable-exception-classes>
                <listeners>
                    <listener ref="MyListener"/>
                </listeners>
            </chunk>
        </tasklet>
        <next on="COMPLETED" to="step2"/>
    </step>
    <step id="step2" >
        <tasklet transaction-manager="transactionManager" task-executor="taskExecutor" allow-start-if-complete="true">
            <chunk reader="DomainItemReader2" writer="DomainItemWriter2" commit-interval="100" skip-limit="10">
                <skippable-exception-classes>
                    <include class="java.lang.Exception"/>
                    <exclude class="java.io.FileNotFoundException"/>
                </skippable-exception-classes>
                <listeners>
                    <listener ref="MyListener2"/>
                </listeners>
            </chunk>
        </tasklet>
    </step>
</job>

我的读者看起来像:

<bean id="billDomainItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
    <property name="resource" value="file:./firstfile.txt" />
    <property name="linesToSkip" value="1" />
    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer">
                <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                        <property name="delimiter">
                        <util:constant static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB"/>
                    </property>
                </bean>
            </property>
            <property name="fieldSetMapper">
                <bean class="com.abc.DomainMapper">
                    <property name="accessJobParam" ref="accessJobParam"/>
                </bean>
            </property>
        </bean>
    </property>
</bean>

我的第二步读者看起来像:

<bean id="DomainItemReader2" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
    <property name="resource" value="file:./secondFile.txt" />
    <property name="linesToSkip" value="1" />
    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer">
                <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                    <!-- <property name="names" value="PRODUCT_ID,NAME,DESCRIPTION,PRICE" />-->
                    <property name="delimiter">
                        <util:constant static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB"/>
                    </property>
                </bean>
            </property>
            <property name="fieldSetMapper">
                <bean class="com.abc.DomainMapper2">
                    <property name="accessJobParam" ref="accessJobParam"/>
                </bean>
            </property>
        </bean>
    </property>
</bean>

任何人都可以告诉我我在哪里做错了,以及为什么它不处理我的第二步文件 . 谢谢

回答(2)

2 years ago

我删除了

allow-start-if-complete="true"`

从我的第二步,并添加

parent="step1"

在我的第二步,它对我来说很好 .

2 years ago

在您的第二个阅读器配置

<property name="fieldSetMapper">
                <bean class="com.DomainMapper2">
                    <property name="accessJobParam" ref="accessJobParam"/>
                </bean>
            </property>

检查bean类映射 <bean class="com.DomainMapper2">

将此bean放在同一个包中或不同的包中 <bean class="com.abc.DomainMapper2">