不能停止弹簧批处理步骤..
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<description>Example job to get you started. It provides a skeleton for a typical batch application.</description>
<bean id="HelloTasklet" class="c.c.c.HelloTasklet" scope="step"/>
<bean id="completionPolicy" class="org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy"/>
<bean id="chunkTimeout" class="org.springframework.batch.repeat.policy.TimeoutTerminationPolicy">
<constructor-arg value="3"/>
</bean>
<bean id="commitCount" class="org.springframework.batch.repeat.policy.SimpleCompletionPolicy">
<property name="chunkSize" value="200" />
</bean>
<bean id="chunkCompletionPolicy" class="org.springframework.batch.repeat.policy.CompositeCompletionPolicy">
<property name="policies">
<list>
<ref bean="chunkTimeout" />
<ref bean="commitCount" />
</list>
</property>
</bean>
<bean id="RandomChunkSizePolicy" class="c.c.c.RandomChunkSizePolicy"/>
<job id="importInvoices" xmlns="http://www.springframework.org/schema/batch">
<listeners>
<listener ref="loggingListener"/>
</listeners>
<step id="vehicleStep" next="hello">
<tasklet>
<chunk reader="vehicleReader" writer="vehicleWriter" chunk-completion-policy="RandomChunkSizePolicy"/>
</tasklet>
</step>
<step id="hello" next="decompress">
<tasklet ref="HelloTasklet" />
</step>
<step id="decompress" next="readWriteInvoices">
<tasklet ref="decompressTasklet" />
</step>
<step id="readWriteInvoices">
<tasklet>
<chunk reader="reader" writer="writer" commit-interval="100" />
</tasklet>
</step>
</job>
<bean id="loggingListener" class="c.c.c.JobLoggerListener"></bean>
<bean id="decompressTasklet" class="c.c.c.DecompressTasklet">
<property name="inputResource" value="file:./input/input.zip" />
<property name="targetDirectory" value="./work/output/" />
<property name="targetFile" value="invoices.txt" />
</bean>
<bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" value="file:./work/output/invoices.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="INVOICE_ID,CUSTOMER_ID,DESCRIPTION,ISSUE_DATE,AMOUNT" />
</bean>
</property>
<property name="fieldSetMapper">
<bean class="c.c.c.InvoiceFieldSetMapper" />
</property>
</bean>
</property>
</bean>
<bean id="writer" class="c.c.c.InvoiceJdbcItemWriter">
<constructor-arg ref="dataSource" />
</bean>
</beans>
并在输入中看到这一点:
The chunk size has been set to 2
Reader
Reader
Writer
[reeeeader, reeeeader]
The chunk size has been set to 2
Reader
Reader
Writer
[reeeeader, reeeeader]
The chunk size has been set to 2
Reader
Reader
Writer
[reeeeader, reeeeader]
..等等。需要建议。
答案 0 :(得分:6)
只有在ItemReader实现中读取空值时,步骤才会停止。您需要确保读取器实现在某个时间点读取并返回null。然后该步骤将自行停止。