Announcement Announcement Module
Collapse
No announcement yet.
Calling Spring Batch jobs from a servlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calling Spring Batch jobs from a servlet

    Hi,

    I used STS (SpringSource Tool Suite) to create a web project based on Spring Batch Admin, and then I added a servlet to that project because I want to call jobs from that servlet. However when I try to invoke jobs from the servlet, the jobs are not being located in the application context...

    Code:
    ServletContext servletContext =this.getServletContext();
    
    WebApplicationContext applicationContext = WebApplicationContextUtils.
                    getRequiredWebApplicationContext(servletContext);
    
    JobLauncher launcher = (JobLauncher) applicationContext
                                    .getBean("jobLauncher");
    
    Job job = (Job) applicationContext.getBean("simpleJob");
    The above code results in the below error...

    Code:
    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'simpleJob' is defined
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:505)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1040)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:272)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:188)
            at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1004)
           at com.wu.interstream.advising.servlets.AdviseAgents.doGet(AdviseAgents.java:75)
    I have attached the web.xml and servlet code to this email.

    SimpleJob is a standard job that comes as part of the Spring Batch Admin template. It is defined in the module-context.xml which is loaded when the Batch Servlet (also an Admin standard) is loaded.

    Thanks in advance for any help,
    Jehan
    Last edited by Jehan99; Nov 10th, 2011, 08:28 AM.
Working...
X