Announcement Announcement Module
Collapse
No announcement yet.
Problems Restart with CompositeItemWriter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems Restart with CompositeItemWriter

    We have a problem with CompositeItemWriter. In particular, we can not handle restart.
    Following an error, the table is stored BATCH_STEP_EXECUTION_CONTEXT only the outcome of writing the second file itemWriterFile2
    (in the field SHORT_CONTEXT is enhanced with {"map":{"entry":[{"string":"FlatFileItemReader.read.count","int":37 },{"string":"FlatFileItemWriter.written","long":2} ,{"string":"FlatFileItemWriter.current.count","lon g":98}]}})

    The outcome of writing the first file is stored where itemWriterFile1?

    The configuration of the job is as follows:

    Code:
    <b:job id="loaderJob" job-repository="jobRepository" restartable="true">
    <b:step id="loaderStep">
    <b:tasklet transaction-manager="batchTransactionManager">
    <b:chunk reader="loaderReader" processor="loaderProcessor" writer="itemWriterComposite" commit-interval="1">
    <b:streams>
    <b:stream ref="fileItemReader"/>
    <b:stream ref="itemWriterFile1"/>
    <b:stream ref="itemWriterFile2"/>
    </ b:streams>
    </ b:chunk>
    </ b:tasklet>
    </ b:step>
    </ b:job>
    
    <bean id="itemWriterComposite" class="org.springframework.batch.item.support.CompositeItemWriter">
    <property name="delegates">
    <list>
    <ref bean="itemWriterFile1" />
    <ref bean="itemWriterFile2" />
    </list>
    </property>
    </bean>
    
    <bean id="itemWriterFile1" class="com.write.ItemFile1" >
    		<property name="delegate">
    			<bean class="org.springframework.batch.item.file.FlatFileItemWriter">
    				 <property name="resource" value="file:target/test-outputs/output1.txt" />
    				 
    				<property name="lineAggregator">
    					<bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
    				</property>
    			</bean>
    		</property>		
    	</bean>
    	
    	<bean id="itemWriterFile2" class="com.write.ItemFile2" >
    		<property name="delegate">
    			<bean class="org.springframework.batch.item.file.FlatFileItemWriter">
    				 <property name="resource" value="file:target/test-outputs/output2.txt" />
    				 
    				<property name="lineAggregator">
    					<bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
    				</property>
    			</bean>
    		</property>		
    	</bean>
    Thanks
    Last edited by xgiangi; Aug 4th, 2011, 10:12 AM.

  • #2
    FlatFileItemWriter (and similar components) has a naming convention for the ExecutionContext keys. You need to override it if yo have two in the same step using the "name" property.

    Comment

    Working...
    X