Spring Batch the same steps in multiple jobs?

I am rather confused by the Spring Package naming conventions using spring -batch 2.1.8.RELEASE.

Main problem:

2 different tasks, but with the same step inside (which will receive different properties), which name is not unique. If I try to do one of the tasks, for example job1. Then it gets the value "file2" for prop2, even if it is defined for job2. (only an example of abstraction with less detailed information about degrees, students, etc.). It is not possible to determine any pattern or reason for this process.

<batch:job id="job1" parent="parentJob"> <batch:step id="copyFile"> <batch:tasklet> <bean class="xxx.xyz.classXXX" scope="step"> <property name="prop1" value="file1" /> </bean> </batch:tasklet> </batch:step> </batch> 

Each task is defined in its own file.

 <batch:job id="job2" parent="parentJob"> <batch:step id="copyFile"> <batch:tasklet> <bean class="xxx.xyz.classXXX" scope="step"> <property name="prop2" value="file2" /> </bean> </batch:tasklet> </batch:step> </batch> 

We got about 80 jobs - each of them has copyFile as a first step. But there are also steps in the middle of each work that should be called the same. Is there any way to avoid these injection-confusion / failure? Besides names such as "copyFile1", "copyFile2", etc.

(names and properties are nothing but smoke and mirrors!)

Do you need more information? I hope my explanations are not so bad. Thank you in advance!

Cheers max.

+4
source share
2 answers

Apparently step identifiers are global in spring package (verified today). They are loaded into the map when creating the context, and since they have the same identifier, the step counted as the last win.

Workaround for this function: use a separate step identifier, for example, with a prefix equal to the batch: job id parameter as follows:

 <batch:job id="job1" parent="parentJob"> <batch:step id="job1_copyFile"> <batch:tasklet> <bean class="xxx.xyz.classXXX" scope="step"> <property name="prop1" value="file1" /> </bean> </batch:tasklet> </batch:step> </batch> <batch:job id="job2" parent="parentJob"> <batch:step id="job2_copyFile"> <batch:tasklet> <bean class="xxx.xyz.classXXX" scope="step"> <property name="prop2" value="file2" /> </bean> </batch:tasklet> </batch:step> </batch> 
+3
source

You have two anonymous beans that override each other since they do not have a set of identifiers, although they have the same class.

Since different parameters do not distinguish between your beans, they are overridden.

Just placing id attributes for your beans should solve your problem.

  <bean id="file1" class="xxx.xyz.classXXX" scope="step"> <property name="prop1" value="file1" /> </bean> 

Hope this helps ...

0
source

All Articles