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

  • Launching job from Tomcat

    I'm trying to launch a job from Tomcat. After someone hits my URL, it fires off this process. Running as a standalone JavaSE application, it works fine. However, when running on Tomcat, it seems like it cannot create certain beans. Any ideas? Does it have to do with paths to the xml files or anything?

    Code:
    final String[] paths = new String[] { "resources/jobs/feedreader.xml", "simple-container-definition.xml" };
    		
    try {
    	final ApplicationContext applicationContext = new ClassPathXmlApplicationContext(paths);
    			
    	JobLauncher jobLauncher = (JobLauncher) applicationContext.getBean("jobLauncher");
    	Job job = (Job) applicationContext.getBean("feedreader");
    	jobLauncher.run(job, new JobParameters());
    } catch (Exception ex) {
    	mLogger.error("error trying to run job");
    	ex.printStackTrace();
    }
    Gives:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobLauncher' defined in class path resource [simple-container-definition.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1362)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:540)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:485)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 51)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:169)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:170)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeansOfType(DefaultListableB eanFactory.java:296)
    at org.springframework.context.support.AbstractApplic ationContext.getBeansOfType(AbstractApplicationCon text.java:950)
    at org.springframework.context.support.AbstractApplic ationContext.registerListeners(AbstractApplication Context.java:711)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:366)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:122)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:76)

  • #2
    Where are you declaring your DataSource? If you're using our simple-container-definition.xml, it references a data-source.xml that must also be in your application context.

    Comment


    • #3
      Everything is in the output folder of my project (build/classes):
      data-source-context.xml
      simple-container-definition.xml
      session-factory.xml
      resources/jobs/feedreader.xml

      I just can't seem to figure out if this behavior is being caused by spring or tomcat

      Comment


      • #4
        Yeah, but you're only loading two in your ApplicationContext, the feedReader.xml, and the container definition. You should load all the ApplicationContexts, or are you using imports for everything?

        Comment


        • #5
          I just looked at the spring code that threw the exception. It should only be thrown when a bean has an init-method on it that doesn't exist. Something like:

          Code:
          <bean id="jobLauncher" class="...SimpleJobLauncher" init-method="doesntExist" />

          Comment


          • #6
            The code snippet that you given is working for me. I ran footballJob using simple-job-launcher-context.xml

            I got JobAlreadyRunningException(try with other job parameters) when i ran second time. Could you please tell me how can i overcome this?
            Please give some code snippet to change jobparameters...

            Comment


            • #7
              I am getting the same exception even after restarting the server:
              org.springframework.batch.core.repository.JobInsta nceAlreadyCompleteException: A job instance already exists and is complete for parameters={}{}{}{}. If you want to run this job again, change the parameters.

              Once i stopped the server, all job processes should be stopped. Is this something due to metadata table datas?

              I commented "<value>${batch.schema.script}</value>" in data-source-context-init.xml because i do not want to create metadata tables each time job is running.

              Comment


              • #8
                Like it says: "If you want to run this job again, change the parameters." You can only run a job instance once by design. Read the manual (http://static.springframework.org/sp...ocs/index.html) and search this forum and you will find plenty more information to help you understand this.

                Comment


                • #9
                  ok, even if the job finished execution successfully with statuscode "completed", we cannot run the same job again unless a change in jobparameter. Please correct me if i am wrong.

                  Comment


                  • #10
                    That's correct, JobInstance = Job + JobParameters, if the job and parameters are the same, then it's the same instance, and if an instance is complete it cannot be run again.

                    Comment

                    Working...
                    X