我正在用两步配置作业,这两个步骤都需要读取不同的文件并将数据转储到数据库。当我启动作业时,它执行了第一步并成功保存数据,第二步没有读取文件。但是在数据库中我可以看到两个步骤状态都是成功的。我的配置看起来像:
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>
任何人都可以告诉我我做错了什么以及为什么它没有处理我的第二步文件。谢谢