Back Forum Reply New

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 :lt;bean id=quot;netWeather-jobquot; parent=quot;simpleJobquot;gt;   lt;property name=quot;stepsquot;gt;       lt;bean id=quot;getWeatherDataquot; parent=quot;simpleStepquot;gt;lt;property name=quot;itemReaderquot;gt;       lt;bean class=quot;uk.co.xyz.batch.core.NetWeatherSourceItemPr  oviderquot;gt;        lt;property name=quot;strFragmentRootElementNamequot; value=quot;locationquot;/gt;        lt;property name=quot;fileGrabberquot; ref=quot;netWeather-diskFileGrabberquot;/gt;        lt;property name=quot;netWeatherMarshallerquot; ref=quot;netWeatherMarshallerquot;/gt;        lt;property name=quot;netWeatherJobLauncherDetailsquot; ref=quot;netWeatherJobLauncherDetailsquot;/gt;        lt;/beangt;lt;/propertygt;lt;property name=quot;itemWriterquot;gt;
lt;bean class=quot;uk.co.xyz.batch.core.NetWeatherSourceItemPr  ocessorquot;gt;
lt;property name=quot;netWeatherServicequot; ref=quot;netWeatherServicequot;/gt;
lt;/beangt;
lt;/propertygt;    lt;/beangt;    lt;/propertygt;lt;/beangt;

lt;bean id=quot;jobLauncherquot; class=quot;org..batch.core.launch.suppo  rt.SimpleJobLauncherquot;gt; lt;property name=quot;jobRepositoryquot; ref=quot;jobRepositoryquot; /gt; lt;property name=quot;taskExecutorquot;gt;   lt;bean class=quot;org..core.task.SimpleAsyncTa  skExecutorquot; /gt; lt;/propertygt;
lt;/beangt;

lt;bean id=quot;netWeather-jobDetailquot; class=quot;org..scheduling.quartz.JobDe  tailBeanquot;gt;   lt;property name=quot;jobClassquot; value=quot;uk.co.abc.batch.core.utils.JobLauncherDetai  lsquot; /gt;   lt;property name=quot;groupquot; value=quot;quartz-batchquot; /gt;   lt;property name=quot;jobDataAsMapquot;gt;       lt;mapgt;lt;entry key=quot;jobNamequot; value=quot;netWeather-jobquot;/gt;lt;entry key=quot;jobLocatorquot; value-ref=quot;jobRegistryquot;/gt;lt;entry key=quot;jobLauncherquot; value-ref=quot;jobLauncherquot;/gt;       lt;/mapgt;   lt;/propertygt;
lt;/beangt;

....

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.

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

Sample :

Code:
lt;bean id=quot;flatFileItemReaderquot; scope=quot;stepquot; class=quot;org..batch.item.file.FlatFileItemReaderquot;gt; lt;property name=quot;resourcequot; value=quot;#{jobParameters[input.file.name]}quot; /gt;
lt;/beangt;
or this one if a previous step caculate the name (and put it in the jobExecutionContext)

Code:
lt;bean id=quot;flatFileItemReaderquot; scope=quot;stepquot; class=quot;org..batch.item.file.FlatFileItemReaderquot;gt; lt;property name=quot;resourcequot; value=quot;#{jobExecutionContext[input.file.name]}quot; /gt;
lt;/beangt;
read the userguide for details : sprin...nce/index.html
¥
Back Forum Reply New