Results 1 to 10 of 10

Thread: Launching job from Tomcat

Hybrid View

  1. #1
    Join Date
    Mar 2008
    Posts
    2

    Default 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. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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.

  3. #3
    Join Date
    Mar 2008
    Posts
    2

    Default

    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

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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?

  5. #5
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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" />

  6. #6

    Default

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

  7. #7

    Default

    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.

  8. #8
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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.

  9. #9

    Default

    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.

  10. #10
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    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.

Posting Permissions

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