如何使用在spring批处理中在另一个作业定义文件中声明的JobID

时间:2014-08-11 08:15:05

标签: xml spring spring-batch

我有3个工作。它们是Job1, Job2 and Job3 Job1必须并行运行Job2Job3 这些作业在单独的作业定义文件中定义如下。

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>

问题是当我启动tomcat服务器时,发生了以下问题。

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

但是,只在一个作业定义文件中声明所有作业时,这是可以的 所以,让我知道有没有办法解决这个问题。

1 个答案:

答案 0 :(得分:0)

尝试此配置

<import resource="classpath*:META-INF/Job2.xml" />
<import resource="classpath*:META-INF/Job3.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>