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

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

    Hi,

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

    Regards,
    Rams

  • #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.

    Comment


    • #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 printTsaklet.java files and i have one servlet.
      the code snippets are here.......................

      uploadservlet.java 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 = launcher.run(job, jobParameters);
      out.println(jobExecution.getExecutionContext());
      out.println(jobExecution.getExitStatus());
      }
      catch(Exception e)
      {
      e.printStackTrace();
      }

      and memory-repository is....

      <bean id="jobRepository-transactionManager"
      class="org.springframework.batch.support.transacti 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" />
      </property>
      </bean>

      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>
      <bean id="world" class="com.mypack.PrintTasklet">
      <property name="message" value=" World!"/>
      </bean>

      <!-- <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>
      <batch:step id="step1">
      <batch:tasklet ref="world"
      transaction-manager="jobRepository-transactionManager" />
      </batch:step>
      </batch:job>

      </beans>

      and PrintTaskLet.java

      @SuppressWarnings("unchecked")
      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
      {
      System.out.print(message);
      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..

      Comment

      Working...
      X