Announcement Announcement Module
Collapse
No announcement yet.
changing file for itemwriter dynamically depends on itemreader item Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • changing file for itemwriter dynamically depends on itemreader item

    Hello,

    I am trying to change dynamically the file to itemwriten depends on item that i have just read in itemreader.
    My idea was change the stepExecutionContext, but I can not access to it from afterRead method...

    Code:
    ...
    <batch:step id="step1job2" next="step2job2" >
    			<batch:tasklet transaction-manager="transactionManager"
    				start-limit="100" >
    				<batch:chunk  reader="visitsItemReader"  writer="visitsXmlItemWriter" commit-interval="1" />
    			</batch:tasklet>
    			<batch:listeners>
    				<batch:listener ref="sufijoFicheroListenner" />
    			</batch:listeners>
    		</batch:step>
    ...
    <bean id="visitsXmlItemWriter" class="org.springframework.batch.item.xml.StaxEventItemWriter" scope="step">
    		<property name="resource" ref="outputVisitasXMLFile" />
    		<property name="marshaller" ref="visitasMarshaller" />
    		<property name="rootTagName" value="visitas" />
    	</bean>
    	<bean id="outputVisitasXMLFile" class="org.springframework.core.io.FileSystemResource"
    		scope="step">
    <!-- I WOULD LIKE TO CHANGE DYNAMICALLY THIS FILE DEPENDS ON ITEMREADER-->
    		<constructor-arg value="/datos/x21b/${#{stepExecutionContext['nombreFichero']}.xml" />
    	</bean>
    thanks

  • #2
    Hi there, Did you manage to find a solution to this problem as I am facing a similar issue!

    Thanks

    Comment


    • #3
      Take a look at the ClassifierCompositeItemWriter. That should let you funnel items to the appropriate ItemWriter based on whatever criteria you need.

      Comment


      • #4
        Hi did you find the solution for this i am also facing this issue

        Comment


        • #5
          Hi there,

          Yes I actually took the advice above and created my own CompositeItemWriter class which has a reference to a Classifier instead of a delegate writer. When it need to decide what writer to use in my CompositeItemWriter I call the classifier.classify() method passing an instance of the item. My Classifier implementation then knows which writer to use depending on the item that has been passed in. Hope that helps. Let me know if you need more info...

          Comment


          • #6
            Hi find the below link somewhat useful

            https://github.com/langmi/spring-batch-examples

            Comment

            Working...
            X