Announcement Announcement Module
Collapse
No announcement yet.
Problem with passing a dynamic file name as JobParameter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with passing a dynamic file name as JobParameter

    Hi
    I need to pass a file name (which is a input to the batch job) as a jobparameter. The reason I want to do this is because for every run of the job the file name will be different (base file name + timestamp when the job starts) and I need to keep track of which job relates to which file.

    I know that we can get the file name from the Jobparameters using late binding feature but what I want is exactly the opposite. I need to pass the filename to the jobparameter and also I am not runnnig the job from command line.

    My config files are :


    <bean id="netWeather-job" parent="simpleJob">
    <property name="steps">
    <bean id="getWeatherData" parent="simpleStep">
    <property name="itemReader">
    <bean class="uk.co.xyz.batch.core.NetWeatherSourceItemPr ovider">
    <property name="strFragmentRootElementName" value="location"/>
    <property name="fileGrabber" ref="netWeather-diskFileGrabber"/>
    <property name="netWeatherMarshaller" ref="netWeatherMarshaller"/>
    <property name="netWeatherJobLauncherDetails" ref="netWeatherJobLauncherDetails"/>
    </bean>
    </property>
    <property name="itemWriter">
    <bean class="uk.co.xyz.batch.core.NetWeatherSourceItemPr ocessor">
    <property name="netWeatherService" ref="netWeatherService"/>
    </bean>
    </property>
    </bean>
    </property>
    </bean>

    <bean id="jobLauncher" class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
    <property name="jobRepository" ref="jobRepository" />
    <property name="taskExecutor">
    <bean class="org.springframework.core.task.SimpleAsyncTa skExecutor" />
    </property>
    </bean>

    <bean id="netWeather-jobDetail" class="org.springframework.scheduling.quartz.JobDe tailBean">
    <property name="jobClass" value="uk.co.abc.batch.core.utils.JobLauncherDetai ls" />
    <property name="group" value="quartz-batch" />
    <property name="jobDataAsMap">
    <map>
    <entry key="jobName" value="netWeather-job"/>
    <entry key="jobLocator" value-ref="jobRegistry"/>
    <entry key="jobLauncher" value-ref="jobLauncher"/>
    </map>
    </property>
    </bean>

    ....

    The JobLauncherDetails class is same as it is in the spring batch samples and its here where the jobparameters are created. But I will get the file name only in the netWeather-job bean using the diskfilegrabber which is a custom class.


    Also is there any way to configure the input file name from the batch admin or is this feature on the project roadmap?




    Any help would be much appreciated.
    Last edited by Hameed; Nov 22nd, 2009, 02:33 PM.

  • #2
    According to what I've read it's possible directly (using jobparameter) or calculating the name in a previous step.

    Sample :
    Code:
    <bean id="flatFileItemReader" scope="step"
      class="org.springframework.batch.item.file.FlatFileItemReader">
      <property name="resource" value="#{jobParameters[input.file.name]}" />
    </bean>
    or this one if a previous step caculate the name (and put it in the jobExecutionContext)
    Code:
    <bean id="flatFileItemReader" scope="step"
      class="org.springframework.batch.item.file.FlatFileItemReader">
      <property name="resource" value="#{jobExecutionContext[input.file.name]}" />
    </bean>
    read the userguide for details : http://static.springsource.org/sprin...nce/index.html

    Comment

    Working...
    X