Monday, 11 August 2014

How to use JobID that is declared in another job definition file in spring batch



I have 3 jobs. They are Job1, Job2 and Job3.

Job1 have to run Job2 and Job3 in parallel.

These jobs are defined in separated job definition files as followings.


Job1.xml



<batch:job id="Job1" restartable="true" >
<batch:step id="step1" next="split">
<batch:tasklet ref="job1.stp01" />
</batch:step>

<batch:split id="split">
<batch:flow>
<batch:step id="flow1" >
<batch:job ref="Job2" job-launcher="simpleJobLauncher" job-parameters-extractor="defaultJobParametersExtractor"/>
</batch:step>
</batch:flow>

<batch:flow>
<batch:step id="flow2">
<batch:job ref="Job3" job-launcher="simpleJobLauncher" job-parameters-extractor="defaultJobParametersExtractor"/>
</batch:step>
</batch:flow>
</batch:split>

</batch:job>


Job2.xml



<batch:job id="Job2" restartable="true">
<batch:step id="Job2.Step01">
<batch:tasklet ref="job2.stp01" />
</batch:step>
</batch:job>


Job3.xml



<batch:job id="Job3" restartable="true">
<batch:step id="Job3.Step01">
<batch:tasklet ref="job3.stp01" />
</batch:step>
</batch:job>


The problem is when I start the tomcat server, the following problem was occurred.



13:33:56,875 ERROR [org.springframework.web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flow1': Cannot resolve reference to bean 'Job2' while setting bean property 'job'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Job2' is defined


But it was okay when all jobs are declared in only one job definition file.

So, let me know that Is there a way to solve this problem.


No comments:

Post a Comment