...//batch:job
...//batch:step
...//batch:tasklet
lt;batch:chunk reader=quot;itemReaderquot; writer=quot;writerFactoryquot;commit-interval=quot;10quot; /gt;
...//batch:tasklet
...//batch:step
...//batch:job
lt;bean id=quot;writerFactoryquot; class=quot;factory.WriterFactoryquot; factory-method=quot;createWriterInstancequot; scope=quot;stepquot;gt;
lt;constructor-arg index=quot;0quot; type=quot;java.lang.Stringquot; value=quot;#{jobParameters['dbJobName']}quot;/gt;
lt;/beangt;
lt;bean id=quot;textItemWriterquot; class=quot;jobs.FlatFileWriterquot; scope=quot;stepquot;gt;
lt;property name=quot;jobNamequot; value=quot;#{jobParameters['dbJobName']}quot;/gt;
lt;/beangt;
lt;bean id=quot;xmlItemWriterquot; class=quot;jobs.XMLWriterquot; scope=quot;stepquot;gt;
lt;property name=quot;jobNamequot; value=quot;#{jobParameters['dbJobName']}quot;/gt;
lt;/beangt;
signature of TextItemWriter : public class TextItemWriter extends FlatFileItemWriterlt;RowMapItemgt; implements StepExecutionListener,ItemStream
I am having the requirement where i am using a factory method to dynamically create an instance of ItemWriters like FlatFileItemWriter and StaxEventItemWriter(for XML).
In afterPropertiesSet i am setting the resource amp; lineAggregator. In write method i am using super.write(items), at this stage i am getting an error quot;Writer must be open before it can be written toquot;.
If i try to override open method by implementing ItemStream, control doesn't enter open method. it is directly going to write method. and throwing that error.
In your step configuration add streams property.
Within that list your writer references. That should work
Below is the sample, add this to your step
lt;streamsgt; lt;stream ref=quot;fileItemWriter1quot;/gt; lt;stream ref=quot;fileItemWriter2quot;/gt; lt;/streamsgt;
thanks for the solution... |