0

I have fifteen job configuration in my spring batch project. The jobs are been called from different source. That means I do not have control over the call.

Ten out of fifteen job perform the same task, therefore I want to create a single configuration file and execute all the ten jobs.

My question is :

Is it possible to dynamically change the job name in the configuration file.

Pragam Shrivastava
  • 1,428
  • 3
  • 13
  • 20
  • Use 1 abstract bean definition for job skeleton and 10 concrete beans with different name, one for job. You might check for alias, too. – Luca Basso Ricci Aug 27 '15 at 13:31

2 Answers2

1

The answer may not be what you are expecting. But I used this technique for a similar situation (not for the batch jobs, though).

You may have multiple bean definitions, pointing to same Java Class and receiving a property value different for each definition. Based on the value of jobSource, you may want perform necessary action needed for that source.

<bean id="job1" class="your.job.class.Here">
    <property name="jobSource" value="source1" />
</bean>

<bean id="job2" class="your.job.class.Here">
    <property name="jobSource" value="source2" />
</bean>

ajoshi
  • 349
  • 2
  • 10
  • user3714034: thanks for your efforts! Do you know any way by which I can change the jobname in the context file on the runtime? – Pragam Shrivastava Aug 27 '15 at 11:48
  • Please check if following links help. The one which shows how to get ExecutionContext: http://stackoverflow.com/questions/8117060/storing-in-jobexecutioncontext-from-tasklet-and-accessing-in-another-tasklet The documentation that provides interface to enable job processing: http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/core/configuration/annotation/EnableBatchProcessing.html – ajoshi Aug 27 '15 at 13:33
0

I created one context file with all the similar job and another file with the common bean definitions. This has helped me in reducing a lot of code works.

Pragam Shrivastava
  • 1,428
  • 3
  • 13
  • 20