-
Feb 16th, 2011, 01:37 AM
#1
Writer must be open before it can be written to
...//batch:job
...//batch:step
...//batch:tasklet
<batch:chunk reader="itemReader" writer="writerFactory" commit-interval="10" />
...//batch:tasklet
...//batch:step
...//batch:job
<bean id="writerFactory" class="factory.WriterFactory" factory-method="createWriterInstance" scope="step">
<constructor-arg index="0" type="java.lang.String" value="#{jobParameters['dbJobName']}"/>
</bean>
<bean id="textItemWriter" class="jobs.FlatFileWriter" scope="step">
<property name="jobName" value="#{jobParameters['dbJobName']}"/>
</bean>
<bean id="xmlItemWriter" class="jobs.XMLWriter" scope="step">
<property name="jobName" value="#{jobParameters['dbJobName']}"/>
</bean>
signature of TextItemWriter : public class TextItemWriter extends FlatFileItemWriter<RowMapItem> 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 & lineAggregator. In write method i am using super.write(items), at this stage i am getting an error "Writer must be open before it can be written to".
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.
Last edited by kamath_sv; Feb 16th, 2011 at 01:42 AM.
-
Feb 16th, 2011, 09:03 AM
#2
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
<streams>
<stream ref="fileItemWriter1"/>
<stream ref="fileItemWriter2"/>
</streams>
-
Feb 23rd, 2011, 07:10 AM
#3
thanks for the solution...
-
Oct 27th, 2011, 07:21 PM
#4
This issue seem to be there for ClassifierCompositeItemWriter too
I am getting
org.springframework.batch.item.WriterNotOpenExcept ion: Writer must be open before it can be written to, when I use ClassifierCompositeItemWriter with FlatFileItemWriter delegates..
And, ClassifierCompositeItemWriter does not have any method setIgnoreItemStream, as suggested for CompositeItemWriter class.
What I am trying to do is to route a domain object to either success or failure report writers based on certain flag in the object. Both the success and failure writers are FlatFileItemWriter instances pointing to different file system resources..
I wonder if there is any fix available to this? If not, is there any alternative, which is almost as simple to code for as ClassifierCompositeItemWriter
-
Oct 27th, 2011, 07:37 PM
#5
As specified in Spring BatchBATCH-836, CompositeItemWriter seem to have a solution using setIgnoreItemStream.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules