Announcement Announcement Module
No announcement yet.
how to run spring batch application using servlet/jsp. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to run spring batch application using servlet/jsp.


    Any body known how to run spring batch application using servlet/jsp and how to deploy spring batch application in webcontainer(tomcat).


  • #2
    Any body known how to run spring batch application using servlet/jsp
    could you be more precise about what you want to do with servlet, JSP, and Spring Batch?

    how to deploy spring batch application in webcontainer(tomcat).
    Spring Batch builds on top of Spring, so you just have to configure a ContextLoaderListener in your web.xml file and declare Spring Batch beans (job repository, job launcher, jobs, etc). Your web controller can then refer to these beans to launch a Spring Batch job on an HTTP request.


    • #3
      Hi arno,

      actually i have one stant alone spring batch application. That application working fine. But now i requirement is, i need to run that application through from the servlet/jsp.

      I have all the files like MEMORY-JOBREPOSITORY.xml, helloWorlJob.xml, one files and i have one servlet.
      the code snippets are here....................... in do get method

      ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("helloWorldJob.xml" );
      context.getAutowireCapableBeanFactory().autowireBe anProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
      org.springframework.batch.core.Job job;
      job = (org.springframework.batch.core.Job) context.getBean("helloWorldJob");

      JobParametersBuilder builder = new JobParametersBuilder();
      JobParameters jobParameters = builder.toJobParameters();
      JobLauncher launcher = new SimpleJobLauncher();
      try {
      JobExecution jobExecution =, jobParameters);
      catch(Exception e)

      and memory-repository is....

      <bean id="jobRepository-transactionManager"
      class=" on.ResourcelessTransactionManager"/>
      <bean id="jobLauncher"
      class="org.springframework.batch.core.launch.suppo rt.SimpleJobLauncher">
      <property name="jobRepository" ref="jobRepository" />
      <property name="taskExecutor">
      <bean class="org.springframework.core.task.SimpleAsyncTa skExecutor" />

      helloWorldJob.xml is......

      <import resource="MEMORY-JOBREPOSITORY.xml"/>
      <!-- <import resource="DB-JOBREPOSITORY.xml"/>-->

      <bean id="hello" class="com.mypack.PrintTasklet">
      <property name="message" value="Hello"/>
      <bean id="world" class="com.mypack.PrintTasklet">
      <property name="message" value=" World!"/>

      <!-- <bean id="dynamicJobParameters"
      class="com.ecomputercoach.DynamicJobParameters" />-->

      <!-- <batch:job id="helloWorldJob" job-repository="jobRepository" incrementer="dynamicJobParameters">-->
      <batch:job id="helloWorldJob" job-repository="jobRepository">
      <batch:step id="step0" next="step1">
      <batch:tasklet ref="hello"
      transaction-manager="jobRepository-transactionManager" />
      <batch:step id="step1">
      <batch:tasklet ref="world"
      transaction-manager="jobRepository-transactionManager" />



      public class PrintTasklet implements Tasklet
      private String message;
      public void setMessage(String message)
      this.message = message;

      public RepeatStatus execute(StepContribution arg0, ChunkContext arg1)throws Exception
      return RepeatStatus.FINISHED;

      can you please check this code and let me know anything do i need to add in web.xml
      please correct me..