Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Batch:Passing some objects from controller to batch-step
    primarykey
    data
    text
    <p>Hello I am a currently new to <a href="http://static.springsource.org/spring-batch/" rel="nofollow">Spring Batch</a>.And i am facing a difficulty which I searched alot but can't find the solution.My requirement is to process N folders through N policy templates.For example first step will check if the Folder Name is according to my policy or not ,second step will check analyse the files mime type inside the folder according to policy template etc etc...I have configured my steps properly. Upto this point the day was having sunshine for me but I am stuck at point where i need to pass values from my controller method to spring batch.Like selected folders by user and the policy templates from database.So my question is how to pass the objects from controller to my first step of batch process.</p> <p>Following is my configuration regarding batch job.</p> <p><strong>applicationContext.xml</strong></p> <pre><code>&lt;!--Batch job configuration starts here--&gt; &lt;bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher" p:jobRepository-ref="jobRepository" p:taskExecutor-ref="taskExecutor"/&gt; &lt;batch:job-repository id="jobRepository" data-source="safeJNDI" transaction-manager="transactionManager" isolation-level-for-create="SERIALIZABLE" max-varchar-length="1000" /&gt; &lt;bean id="jobOperator" class="org.springframework.batch.core.launch.support.SimpleJobOperator"&gt; &lt;property name="jobExplorer"&gt; &lt;bean class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"&gt; &lt;property name="dataSource" ref="safeJNDI" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="jobRepository" ref="jobRepository" /&gt; &lt;property name="jobLauncher" ref="jobLauncher" /&gt; &lt;property name="jobRegistry" ref="jobRegistry"/&gt; &lt;/bean&gt; &lt;bean id="jobRegistry" class="org.springframework.batch.core.configuration.support.MapJobRegistry"/&gt; &lt;batch:job id="templateMatchingJob" restartable="true"&gt; &lt;batch:listeners&gt; &lt;batch:listener ref="templateMatchingJobListener"&gt;&lt;/batch:listener&gt; &lt;/batch:listeners&gt; &lt;batch:step id="basicRuleCheckerStep"&gt; &lt;batch:tasklet ref="basicRuleCheckerTasklet" /&gt; &lt;batch:next on="COMPLETED" to="checkMainObjectStep" /&gt; &lt;batch:next on="FAILED" to="logAndShowErrorMessage" /&gt; &lt;batch:listeners&gt; &lt;batch:listener ref="basicRuleCheckerListener"&gt;&lt;/batch:listener&gt; &lt;/batch:listeners&gt; &lt;/batch:step&gt; &lt;batch:step id="checkMainObjectStep"&gt; &lt;batch:tasklet ref="mainObjectCheckerTasklet" /&gt; &lt;batch:next on="COMPLETED" to="checkDBXML" /&gt; &lt;batch:next on="FAILED" to="logAndShowErrorMessage" /&gt; &lt;batch:listeners&gt; &lt;batch:listener ref="mainObjectCheckerListener"&gt;&lt;/batch:listener&gt; &lt;/batch:listeners&gt; &lt;/batch:step&gt; &lt;batch:step id="checkDBXML"&gt; &lt;batch:tasklet ref="dbXMLCheckerTasklet" /&gt; &lt;batch:next on="COMPLETED" to="checkPDIXML" /&gt; &lt;batch:next on="FAILED" to="logAndShowErrorMessage" /&gt; &lt;batch:listeners&gt; &lt;batch:listener ref="dbXMLCheckerListener"&gt;&lt;/batch:listener&gt; &lt;/batch:listeners&gt; &lt;/batch:step&gt; &lt;batch:step id="checkPDIXML"&gt; &lt;batch:tasklet ref="pdiXMLCheckerTasklet" /&gt; &lt;!-- the next is enclosure checking --&gt; &lt;batch:next on="COMPLETED" to="logAndShowErrorMessage" /&gt; &lt;batch:next on="FAILED" to="logAndShowErrorMessage" /&gt; &lt;batch:listeners&gt; &lt;batch:listener ref="pdiXMLCheckerListener"&gt;&lt;/batch:listener&gt; &lt;/batch:listeners&gt; &lt;/batch:step&gt; &lt;batch:step id="logAndShowErrorMessage"&gt; &lt;batch:tasklet ref="logAndShowErrorTasklet" /&gt; &lt;batch:listeners&gt; &lt;batch:listener ref="logAndShowErrorListener"&gt;&lt;/batch:listener&gt; &lt;/batch:listeners&gt; &lt;/batch:step&gt; &lt;/batch:job&gt; &lt;!--Tasklets for template Matching starts here--&gt; &lt;bean id="basicRuleCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.BasicRuleCheckerTasklet"/&gt; &lt;bean id="mainObjectCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.MainObjectCheckerTasklet"&gt; &lt;/bean&gt; &lt;bean id="pdiXMLCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.PDIXMLCheckerTasklet"/&gt; &lt;bean id="dbXMLCheckerTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.DBXMLCheckerTasklet"/&gt; &lt;bean id="logAndShowErrorTasklet" class="com.hcdc.coedp.safe.domain.batch.templateMatching.LogAndShowErrorTasklet"/&gt; &lt;!--Tasklets for template Matching ends here--&gt; &lt;!--Listeners for each step in Batch Template Matching starts here--&gt; &lt;bean id="basicRuleCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.BasicRuleCheckerListener"/&gt; &lt;bean id="mainObjectCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.MainObjectCheckerListener"/&gt; &lt;bean id="pdiXMLCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.PDIXMLCheckerListener"/&gt; &lt;bean id="dbXMLCheckerListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.DBXMLCheckerListener"/&gt; &lt;bean id="logAndShowErrorListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.LogAndShowErrorListener"/&gt; &lt;bean id="templateMatchingJobListener" class="com.hcdc.coedp.safe.domain.batch.templateMatching.listener.TemplateMatchingJobListener" /&gt; &lt;!--Listeners for each step in Batch Template Matching ends here--&gt; </code></pre> <p>Following is my controller method:</p> <p><strong>BatchJobController.java</strong></p> <pre><code> @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())); } </code></pre> <p>I am sorry for my bad English but I was not getting any better way of putting this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload