1

您好,我目前是Spring Batch的新手。我遇到了一个困难,我搜索了很多但找不到解决方案。我的要求是通过 N 个策略模板处理 N 个文件夹。例如,第一步将检查文件夹名称是否是否根据我的策略,第二步将根据策略模板等检查分析文件夹内的文件 mime 类型等...我已经正确配置了我的步骤。到目前为止,这一天对我来说是阳光明媚,但我被困在我需要将值从我的控制器方法传递到弹簧批处理的地方。就像用户选择的文件夹和数据库中的策略模板一样。所以我的问题是如何传递对象从控制器到我的批处理的第一步。

以下是我关于批处理作业的配置。

应用程序上下文.xml

<!--Batch job configuration starts here-->
    <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
          p:jobRepository-ref="jobRepository" 
          p:taskExecutor-ref="taskExecutor"/>

    <batch:job-repository id="jobRepository"
                          data-source="safeJNDI"
                          transaction-manager="transactionManager"
                          isolation-level-for-create="SERIALIZABLE"
                          max-varchar-length="1000"
    />

    <bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator">
        <property name="jobExplorer">
            <bean class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
                <property name="dataSource" ref="safeJNDI" />
            </bean>
        </property>
        <property name="jobRepository" ref="jobRepository" />
        <property name="jobLauncher" ref="jobLauncher" />
        <property name="jobRegistry" ref="jobRegistry"/>
    </bean>
    <bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/>


    <batch:job id="templateMatchingJob" restartable="true">
        <batch:listeners>
            <batch:listener ref="templateMatchingJobListener"></batch:listener>
        </batch:listeners>

       <batch:step id="basicRuleCheckerStep">

            <batch:tasklet ref="basicRuleCheckerTasklet" />
            <batch:next on="COMPLETED" to="checkMainObjectStep" />
            <batch:next on="FAILED" to="logAndShowErrorMessage" />
            <batch:listeners>
                <batch:listener ref="basicRuleCheckerListener"></batch:listener>
            </batch:listeners>

        </batch:step>

        <batch:step id="checkMainObjectStep">
            <batch:tasklet ref="mainObjectCheckerTasklet" />
            <batch:next on="COMPLETED" to="checkDBXML" />
            <batch:next on="FAILED" to="logAndShowErrorMessage" />

            <batch:listeners>
                <batch:listener ref="mainObjectCheckerListener"></batch:listener>
            </batch:listeners>
        </batch:step>
        <batch:step id="checkDBXML">
            <batch:tasklet ref="dbXMLCheckerTasklet" />
            <batch:next on="COMPLETED" to="checkPDIXML" />
            <batch:next on="FAILED" to="logAndShowErrorMessage" />
            <batch:listeners>
                <batch:listener ref="dbXMLCheckerListener"></batch:listener>
            </batch:listeners>
        </batch:step>
        <batch:step id="checkPDIXML">
            <batch:tasklet ref="pdiXMLCheckerTasklet" />
            <!-- the next is enclosure checking -->
            <batch:next on="COMPLETED" to="logAndShowErrorMessage" />
            <batch:next on="FAILED" to="logAndShowErrorMessage" />

            <batch:listeners>
                <batch:listener ref="pdiXMLCheckerListener"></batch:listener>
            </batch:listeners>
        </batch:step>
        <batch:step id="logAndShowErrorMessage">
            <batch:tasklet ref="logAndShowErrorTasklet" />
            <batch:listeners>
                <batch:listener ref="logAndShowErrorListener"></batch:listener>
            </batch:listeners>
        </batch:step>
    </batch:job>

   <!--Tasklets for template Matching starts here-->
    <bean id="basicRuleCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.BasicRuleCheckerTasklet"/>
    <bean id="mainObjectCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.MainObjectCheckerTasklet">

        </bean>
    <bean id="pdiXMLCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.PDIXMLCheckerTasklet"/>
    <bean id="dbXMLCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.DBXMLCheckerTasklet"/>
    <bean id="logAndShowErrorTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.LogAndShowErrorTasklet"/>
   <!--Tasklets for template Matching ends here-->

   <!--Listeners for each step in Batch Template Matching starts here-->
    <bean id="basicRuleCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.BasicRuleCheckerListener"/>
    <bean id="mainObjectCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.MainObjectCheckerListener"/>
    <bean id="pdiXMLCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.PDIXMLCheckerListener"/>
    <bean id="dbXMLCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.DBXMLCheckerListener"/>
    <bean id="logAndShowErrorListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.LogAndShowErrorListener"/>
    <bean id="templateMatchingJobListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.TemplateMatchingJobListener" />
   <!--Listeners for each step in Batch Template Matching ends here-->

以下是我的控制器方法:

批处理作业控制器.java

 @RequestMapping(value = "/decision/batch", method = RequestMethod.POST)
    @ExceptionHandler(value = {GenericException.class})
    public ModelAndView batchMoveFolder(@ModelAttribute(KEY_LOGGED_IN_USER) User whoLoggedIn,      @RequestParam String action, ModelMap model, HttpServletRequest request) 
  {
     //Getting the selected folder list


         /** Details omitted for clarity**/

    //Getting the templates available in database

         /** Details omitted for clarity**/

    //Starting the job

    jobLauncher.run(job,new JobParametersBuilder().addDate(new Date()));   
   }

我很抱歉我的英语不好,但我没有得到更好的表达方式。

4

0 回答 0