Announcement Announcement Module
Collapse
No announcement yet.
BeanWrapperFieldExtractor - Reading names from external file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanWrapperFieldExtractor - Reading names from external file

    Hi all, I am new to Spring Batch and have had a fair bit of fun getting an application working that I am happy with. The only hurdle I've come across so far is how to pass in field names to the BeanWrapperFieldExtractor at runtime.

    I would like to have these stored in an external XML file as follows:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <OutputMapping>
    	<Name>Customer Output Mapping File</Name>
    	<Type>csv</Type>
    	<Field>
    		<Name>id</Name>
    		<Position>0</Position>
    	</Field>
    	<Field>
    		<Name>name</Name>
    		<Position>1</Position>
    	</Field>	
    	<Field>
    		<Name>address</Name>
    		<Position>2</Position>
    	</Field>
    </OutputMapping>
    At the moment my job.xml uses the following call:

    Code:
    <beans:bean id="cptyWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
    	<beans:property name="resource" value="file:target/output.txt" />
    	<beans:property name="lineAggregator">
    		<beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
    			<beans:property name="delimiter" value="," />
    			<beans:property name="fieldExtractor">
    				<beans:bean class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
    					<!-- TODO Refactor to read in output format from XML file -->
    					<beans:property name="names" value="name,id,address" />
    				</beans:bean>
    			</beans:property>
    		</beans:bean>
    	</beans:property>
    </beans:bean>
    Do I need to create a class that extends FieldExtractor and set up the XML reading myself? Appreciate any advice or pointers anyone can offer please.


    Thanks,
    Jordan
Working...
X