Back Forum Reply New

How to write skipped data to itemWriter inside a SkipListener

I have a SkipListener set up and I inject an itemWriter into it. When I use the itemWriter, I get:

org..batch.item.WriterNotOpenExcept  ion: Writer must be open before it can be written to

How do I handle this situation? I read a posting that suggested opening it in an earlier step, but I can't see how to do this...

Suggestions gratefully recieved.

Cheers,

Alph

Registering the writer as a stream for the chunk worked.Code:
lt;bean id= quot;passthroughLineAggregatorquot; class=quot;fm.PassThroughLineAggregatorquot; /gt;
lt;bean id=quot;errorItemWriterquot;       class=quot;org..batch.item.file.FlatFileItemWriterquot;       p:resource-ref=quot;errorOutputResourcequot;       p:lineAggregator-ref=quot;passthroughLineAggregatorquot;       p:shouldDeleteIfExists=quot;truequot; /gt;
lt;bean id=quot;skipListenerquot; class=quot;fm.SkipListenerquot;     p:writer-ref=quot;errorItemWriterquot; /gt;
lt;batch:job id=quot;jobquot;gt;   lt;batch:step id=quot;loadquot;gt;
     lt;batch:taskletgt;
       lt;batch:chunk skip-limit=quot;10quot;         reader=quot;itemReaderquot;         writer=quot;itemWriterquot;         processor=quot;validatingItemProcessorquot;         commit-interval=quot;1quot;gt;         lt;batch:streamsgt;lt;batch:stream ref=quot;errorItemWriterquot;/gt;         lt;/batch:streamsgt;         lt;batch:skippable-exception-classesgt;org..batch.item.file.FlatFileParseExceptionorg..batch.item.validator.ValidationException         lt;/batch:skippable-exception-classesgt;       lt;/batch:chunkgt;       lt;batch:listenersgt;         lt;batch:listener ref=quot;skipListenerquot;/gt;       lt;/batch:listenersgt;     lt;/batch:taskletgt;   lt;/batch:stepgt; lt;/batch:jobgt;Can you please provide details on your skipListener implementation?
I am trying to do the same thing, except on db write exceptions.

.au/w...-spring-batch/

Thanks for the info. I tried similar skip listener but it is throwing exceptions. I am using SB 2.111:58:30,758 ERROR lt;gt; [support.CommandLineJobRunner] Job Terminated in error: Error creating bean with name 'businessLoad': Cannot create inner bean '(inner bean)' of type [org..batch.core.listener.StepListen  erFactoryBean] while setting bean property 'listeners' with key [0]; nested exception is org..beans.factory.BeanCreationExce  ption: Error creating bean with name '(inner bean)': Cannot resolve reference to bean 'skipListener' while setting bean property 'delegate'; nested exception is org..beans.factory.BeanCreationExce  ption: Error creating bean with name 'skipListener' defined in class path resource [BusinessJob.xml]: Error setting property values; nested exception is org..beans.NotWritablePropertyExcep  tion: Invalid property 'writer' of bean class [com.xx.CompositeItemFailureSkipListener]: Bean property 'writer' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

job setup
lt;bean id=quot;skipListenerquot; class=quot;com.xx.CompositeItemFailureSkipListenerquot; p:writer-ref=quot;skipWriterquot;/gt;

lt;bean id=quot;skipWriterquot; class=quot;org..batch.item.file.FlatFil  eItemWriterquot;gt;
lt;property name=quot;resourcequot; value=quot;file:/Skipped.txtquot; /gt;
lt;property name=quot;lineAggregatorquot;gt;
lt;bean class=quot;org..batch.item.file.transfo  rm.DelimitedLineAggregatorquot; gt;lt;property name=quot;fieldExtractorquot;gt;    lt;bean class=quot;org..batch.item.file.transfo  rm.BeanWrapperFieldExtractorquot;gt;
lt;property name=quot;namesquot; value=quot;business,name,numberquot; /gt;    lt;/beangt;lt;/propertygt;
lt;/beangt;
lt;/propertygt;
lt;/beangt;CompositeItemFailureSkipListener method.

private FlatFileItemWriterlt;Businessgt; writer = new FlatFileItemWriterlt;Businessgt;();public void onSkipInWrite(Business business, Throwable t) throws Exception {   writer.write(Collections.singletonList(business)); }

The error message says: 'Bean property 'writer' is not writable...'

YOu have declared writer to be private:

private FlatFileItemWriterlt;Businessgt; writer

It can't be set by the context.

Make it public.

HTH

It's proabably also worth looking at @Required.

BOB

.transentia.sb

import org..batch.core.listener.SkipListen  erSupport

public class SkipListener extends SkipListenerSupportlt;MultilineRecord, Objectgt; {
def writer
@Override public void onSkipInProcess(MultilineRecord item, Throwable t) {   writer.write ( [ item ] ) }
}
¥
Back Forum Reply New