Announcement Announcement Module
Collapse
No announcement yet.
Help Creating Step scoped Files Dynamically. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help Creating Step scoped Files Dynamically.

    Hi All,

    I have a requirement to create files dynamically and write respective records to each file.

    For example, my input file contains records of type A,B,C,D,... and all the records of type A to be written to one file, B to another file and so on.
    I have no idea how many type of records will be there in the input file.
    There can be many Output files.

    Currently I have configured 10 writers(each writer associated with one file) and able to achieve records to be written to respective files.Each writer being invoked by multiple threads.

    Is there a way that I can create step scoped files dynamically?

    Thanks in advance for any help.

  • #2
    Step scoped beans are (by definition) one instance per step. You could create your ItemWriters dynamically in a custom writer (just remember to make calls to open, update and close an the appropriate times). Or if you really wanted to use Spring to configure them all you could use prototype scope, and maybe a factory wrapping the dependency lookup that you would need to do to retrieve a new instance. You would still need to call open, update, close.

    Comment


    • #3
      Thanks Dave. Thanks for the clue.

      One questions is how to retrive the instance of Factory bean itself?
      I tried following as said in the docs, but this throws an exception.

      Code:
      	<bean id="rapidCompositeFileItemWriter" class="com.....writer.RapidFileCompositeItemWriter">
      		<property name="jobContext" ref="jobContextRef"/>
      		<property name="sessionWriters" ref="sessionWritersRef"/>
      		<property name="writerFactory" ref="&inboundOutboundWriterFactoryBean"></property>
      	</bean>
      
      
      <util:list id="sessionWritersRef">
        <ref local="inboundOutboundWriterFactoryBean"/>
        <ref local="inboundOutboundWriterFactoryBean"/>
      .
      .
      </util:list>
      
      <bean id="inboundOutboundWriterFactoryBean" class="com.......writer.InboundOutboundWriterFactory" p:inboundOutboundWriter-ref="inboundOutBoundWriterRef"/>
      
      <bean id="inboundOutBoundWriterRef" class="com.....writer.InboundOutBoundWriter" scope="prototype">
      	<constructor-arg ref="flatFileWriterRef"></constructor-arg>
      	<constructor-arg ref="flatFileWriterRef"></constructor-arg>
      </bean>
      Last edited by anish555; Sep 21st, 2010, 03:28 PM.

      Comment


      • #4
        I wouldn't expect you to have to dereference with "&" (that only applies to FactoryBean instances, and there is no need for one here - it's just a factory with an application context in it).

        Comment


        • #5
          Thanks Dave it works.

          Initially I was trying to do with FactoryBean implementation and was curious to retrive FactoryBean instance.

          Comment

          Working...
          X