Announcement Announcement Module
No announcement yet.
Extending ItemReader and LineMapper to include additional properties Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extending ItemReader and LineMapper to include additional properties

    Hi all, I am still really new to Spring Batch and am having some trouble solving a problem that I am hoping I can get some guidance on please.

    I am trying to build a semi-generic input file reader that uses an external XML file as the field mapping rather than including it within the Spring job itself. I have this working fairly well however it required me to perform the XML mapping read within the LineMapper (in this case an implementation of FieldSetMapper) and as I get high volumes of data this won't work.

    What I would ideally like to do is the following:

    1. Call the job from the command line with a parameter containing the mapping file:

    mvn clean compile exec:java -Dexec.args="processingJob.xml processData DataMappingTypeA.xml"
    I am able to pass the parameter to the reader with the following config:

    <beans:property name="inputFile" value="#{jobParameters['inputFile']}" />
    I would like the reader to create an object from the mapping file and then pass this object to the FieldSetMapper so that it knows how to map the input record to the domain object.

    I have tried extending the FlatFileItemReader class to no avail, I have even tried creating a copy of the frameworks FlatFileItemReader class but when I do this I can't work out how to pass the map object to the LineMapper. It uses the following setter:

    public void setLineMapper(LineMapper<T> lineMapper) {
    		this.lineMapper = lineMapper;
    I've tried to add a new property to my FieldSetMapper implementation however I still can't perform the following:

    public void setLineMapper(LineMapper<T> lineMapper) {
    		this.lineMapper = lineMapper;
    This fails as LineMapper does not contain the map property, I can't get my head around the inheritance and how my FieldSetMapper relates to this LineMapper property.

    So, does anyone have any suggestions on either:

    A) How I can pass the map object through to my FieldSetMapper object? or
    B) A better solution for what I am trying to achieve without the messy solution?

    All I really want to do is import an XML mapping file at runtime based on a filename provided within the command line arguments, convert this in to an object and then make this available for the reader and linemapper (and eventually potentially the writer as well). Am I missing something obvious?

    Thanks a lot,