Announcement Announcement Module
Collapse
No announcement yet.
Cannot autowired job from web container Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cannot autowired job from web container

    First of all, thank you for such awesome product and if my question is redundant please link me to an good answer and I apologize.

    I am trying to launch a job from web container(using Spring Batch Admin) like it is here:

    http://static.springsource.org/sprin...omWebContainer

    I have put my own job file in src/main/resources/spring/batch/jobs/*.xml and in order for the dataSource, jobRepository, job launcher, etc. to get loaded in the bean lifecycle, I copy and paste the file simple-job-launcher-context.xml from the example and put it in src/main/resources/spring/batch/bootstrap/manager/simple-job-launcher-context.xml

    However, I have a problem autowired my job in the controller.
    2011-02-16 16:26:36,622 ERROR [org.springframework.web.servlet.DispatcherServlet] - <Context initialization failed>
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'defaultAnnotationHandlerMapping' defined in URL [jar:file:/C:/workspace-api-proven-direct/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/api-proven-direct/WEB-INF/lib/spring-batch-admin-resources-1.2.0.RELEASE.jar!/META-INF/spring/batch/servlet/resources/resources-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobLauncherController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Could not autowire field: org.springframework.batch.core.Job com.pictage.provendirect.web.JobLauncherController .job; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [org.springframework.batch.core.Job] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Aut owired(required=true), @org.springframework.beans.factory.annotation.Qual ifier(value=orderStatus)}

    Here is my controller, verbatim to the example:

    Code:
    @Controller
    public class JobLauncherController {
        
        @Autowired
        JobLauncher jobLauncher; 
        
        @Autowired
        @Qualifier("orderStatus")
        Job job; 
        
        @RequestMapping("/jobLauncher.html")
        public void handle() throws Exception{
    	jobLauncher.run(job, new JobParameters()); 
        }
    }
    Before I added the controller, I can launch Spring Batch Admin with my custom job file as shown here:

    2011-02-16 16:26:34,680 INFO [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - <Loading XML bean definitions from file [C:\workspace-api-proven-direct\.metadata\.plugins\org.eclipse.wst.server.c ore\tmp1\wtpwebapps\api-proven-direct\WEB-INF\classes\META-INF\spring\batch\jobs\pdorderJob.xml]>

    2011-02-16 16:26:34,772 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Overriding bean definition for bean 'pdorderJob': replacing [Generic bean: class [org.springframework.batch.core.configuration.xml.S impleFlowFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.batch.core.configuration.xml.J obParserJobFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]>

    2011-02-16 16:26:34,811 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Overriding bean definition for bean 'orderStatus': replacing [Generic bean: class [org.springframework.batch.core.configuration.xml.S impleFlowFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.batch.core.configuration.xml.J obParserJobFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]>
    201
    1. Why doesn't my jobs available in the web context?
    2. My plan is to hook my controller to run my job periodically using the Spring 3.0 scheduler like here: http://blog.springsource.com/2010/01...in-spring-3-0/
    Would that work?

    Any help would be appreciated!!

  • #2
    having the same issue, did you come right?

    Comment

    Working...
    X