Announcement Announcement Module
No announcement yet.
Passing filename to FlatFileItemReader with JobParameters Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

    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">
    <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 id="inputFile" class="org.springframework.batch.core.resource.Ste pExecutionResourceProxy">
    <property name="filePattern" value="//"/>

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


    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("", 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?


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

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