Announcement Announcement Module
Collapse
No announcement yet.
Passing filename to FlatFileItemReader with JobParameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing filename to FlatFileItemReader with JobParameters

    I want to dynamically set the resource property of FileItemReader each time my job is run by adding the filename in jobParameters. I have tried doing this according to the documentation:

    http://static.springframework.org/sp...e.html#d0e1694

    My problem is that the value in jobParameters is ignored and the default value from applicationContext.xml is read each time.

    some of the job-xml:
    <bean id="myJob" parent="simpleJob">
    <property name="steps">
    <list>
    <bean id="fileload" parent="simpleStep">
    <property name="listeners" ref="inputFile" />
    <property name="commitInterval" value="${job.commit.interval}" />
    <property name="startLimit" value="100" />
    <property name="itemReader" ref="myFileItemReader" />
    <property name="itemWriter">
    <bean class="test.MyItemWriter">
    <property name="myDao">
    <bean class="test.MyJdbcDao">
    <property name="dataSource" ref="dataSource" />
    </bean>
    </property>
    </bean>
    </property>
    </bean>
    </list>
    </property>
    </bean>

    <bean id="inputFile" class="org.springframework.batch.core.resource.Ste pExecutionResourceProxy">
    <property name="filePattern" value="//%file.name%"/>
    </bean>

    <bean id="myFileItemReader" class="org.springframework.batch.item.file.FlatFil eItemReader">
    <property name="resource" value="classpath:data/myJob/input/${my.file.name}" />

    (etc)

    java:
    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("file.name", file.getAbsolutePath());

    JobExecution jobExecution = getJobLauncher().run(getJob(), builder.toJobParameters());

    I can't find anymore documentation or forum threads on this. I've even stepped thru the spring batch code and FileItemReader doesn't seem to get it's resource from StepExecutionResourceProxy anywhere...

    How's one supposed to set filteitemwriter's resource dynamically from jobparameters?

    /D

  • #2
    You haven't wired the proxy resource into your item reader, like this:

    Code:
    <bean id="myFileItemReader" class="org.springframework.batch.item.file.FlatFil eItemReader">
        <property name="resource" ref="inputFile"/>
    </bean>
    (Please use [code][/code] tags to post code and stack traces.)

    Comment

    Working...
    X