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

  • Problem with passing a dynamic file name as JobParameter

    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=" ovider">
    <property name="strFragmentRootElementName" value="location"/>
    <property name="fileGrabber" ref="netWeather-diskFileGrabber"/>
    <property name="netWeatherMarshaller" ref="netWeatherMarshaller"/>
    <property name="netWeatherJobLauncherDetails" ref="netWeatherJobLauncherDetails"/>
    <property name="itemWriter">
    <bean class=" ocessor">
    <property name="netWeatherService" ref="netWeatherService"/>

    <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" />

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


    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, 03:33 PM.

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

    Sample :
    <bean id="flatFileItemReader" scope="step"
      <property name="resource" value="#{jobParameters[]}" />
    or this one if a previous step caculate the name (and put it in the jobExecutionContext)
    <bean id="flatFileItemReader" scope="step"
      <property name="resource" value="#{jobExecutionContext[]}" />
    read the userguide for details :