Results 1 to 3 of 3

Thread: how to run spring batch application using servlet/jsp.

  1. #1

    Default 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. #2
    Join Date
    Dec 2005
    Location
    Lyon, France
    Posts
    311

    Default

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

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •