Hi, I am new to SB.
I need some details on how to configure a FlatFileItemWriter with skipListener.
I need to get the failed input record(skipped) and write it to a flat file. I checked the forums, but did not find details. I am not sure if I have the correct approach. Here is what I have setup so far.
<job id="testJob" >
<step id="testLoad">
<tasklet>
<chunk reader="testReader" writer="compositeWriter" commit-interval="10" skip-limit="1000">
<streams>
<stream ref="testReader"/>
<stream ref="dbWriter"/>
<stream ref="ffErrorWriter"/>
</streams>
<skippable-exception-classes>
<include class="org.springframework.batch.item.file.FlatFil eParseException" />
<include class="org.springframework.batch.item.WriteFailedE xception" />
<include class="java.lang.RuntimeException"/>
<include class="java.lang.Exception"/>
<include class="org.hibernate.exception.ConstraintViolation Exception"/>
<include class="org.springframework.dao.DataIntegrityViolat ionException"/>
</skippable-exception-classes>
</chunk>
<listeners>
<listener ref="skipListener"/>
</listeners>
</tasklet>
</step>
</job>
<bean id="compositeWriter" class="org.springframework.batch.item.support.Comp ositeItemWriter">
<property name="delegates">
<list>
<ref bean="dbWriter" />
<ref bean="ffErrorWriter" />
</list>
</property>
</bean>
<bean id="skipListener" class="some custom class implements SkipListener" >
(Need help here. How to pass the input record and configure the ffitem writer
public class CustomSkipListener implements SkipListener<Object, Object> {
private String inputRecord;
public void onSkipInWrite(Object arg0, Throwable arg1) {
logger.error("Encountered error in write, Exception is:"+ arg1.getMessage()+"Item that failed:"+arg0.toString());
// how to get the raw input record not the object which failed during write to db and How to hook it to ffitem writer as a passthrough.
}
)
<bean id="ffErrorWriter" class="org.springframework.batch.item.file.FlatFil eItemWriter">
<property name="resource" value="file:Skipped.txt" />
<property name="lineAggregator">
<bean class="org.springframework.batch.item.file.transfo rm.PassThroughLineAggregator" />
</property>
</bean>
< bean for testReader> Read input from flat file
< bean for dbWriter> Write a record using hibernate.


Reply With Quote
