Thanks Arno, I have implemented it, but still i get all the records in a single output file.. I have commit-interval to 2 and itemCountLimitPerResource also 2..
Can, you please help me, pointing to where i am going wrong. my job configuration file is..
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<import resource="../Memory-JobRepository.xml"/>
<job id="headerFooterSample" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk reader="reader" writer="writer" commit-interval="2">
<streams>
<stream ref="reader"/>
<stream ref="mywriter"/>
</streams>
</chunk>
<listeners>
<listener ref="footerCallback"/>
<listener ref="headerCopier"/>
</listeners>
</tasklet>
</step>
</job>
<bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="resource" ref="inputResource" />
<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" value="," />
</bean>
</property>
<property name="fieldSetMapper">
<bean
class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper" />
</property>
</bean>
</property>
<property name="skippedLinesCallback" ref="headerCopier" />
<property name="linesToSkip" value="1" />
</bean>
<bean id="writer" class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
<!-- <property name="resource" ref="outputResource" /> -->
<property name="lineAggregator">
<!-- <bean
class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />-->
<bean class="org.springframework.batch.sample.support.MyLineAggregator" />
</property>
<property name="headerCallback" ref="headerCopier" />
<property name="footerCallback" ref="footerCallback" />
</bean>
<bean id="footerCallback" class="org.springframework.batch.sample.support.SummaryFooterCallback" />
<bean id="headerCopier"
class="org.springframework.batch.sample.support.HeaderCopyCallback" />
<bean id="inputResource" class="org.springframework.core.io.ClassPathResource">
<constructor-arg type="java.lang.String"
value="data/input.txt" />
</bean>
<bean id="outputResource" class="org.springframework.core.io.FileSystemResource" scope="step">
<!-- <constructor-arg type="java.lang.String"
value="target/test-outputs/headerFooterOutput.txt" /> -->
<constructor-arg value="#{jobParameters[file.name]}.dat"/>
</bean>
<bean id="mywriter" class="org.springframework.batch.item.file.MultiResourceItemWriter">
<property name="delegate" ref="writer" />
<property name="itemCountLimitPerResource" value="2" />
<property name="resource" ref="outputResource" />
</bean>
</beans>
My input file contains 10 lines..