Announcement Announcement Module
Collapse
No announcement yet.
Spring exception while using quartz in web app Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring exception while using quartz in web app

    Hi,

    While loading the scheduler through the web app, application is throwing the below error.
    2007-05-29 19:41:16,567 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scheduler' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'cronProperties' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'cronProperties' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'jobDetail1' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobDetail1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: java.lang.String.run()
    Caused by:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'cronProperties' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'jobDetail1' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobDetail1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: java.lang.String.run()
    Caused by:
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobDetail1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: java.lang.String.run()
    Caused by:
    java.lang.NoSuchMethodException: java.lang.String.run()
    at java.lang.Class.getMethod(Class.java:1581)


    Properties
    Code:
    web.xml
    
    <!-- Leave the listener commented-out if using JBoss -->
    	
         	<listener>
    		<listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
    	</listener>
    	
    
    
    --------------------------	
    applicationcontext.xml
    
    <beans>
    
    	<!-- Quartz Scheduler, with pre-registered triggers -->
    	<!-- Will automatically start scheduling on context startup -->
    	<bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
    	<property name="jobDetail" ref="cronProperties" />
    	</bean>
     
    	<!-- Trigger for the job defined above -->
    	<!-- Registered by the 'scheduler' bean -->
    	<bean id="cronProperties" class="org.springframework.scheduling.quartz.CronTriggerBean">
    		<property name="jobDetail" ref="jobDetail1"/>
    		<property name="cronExpression" value="0/5 * * * * ?"/>
    	</bean>
    	
    <bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      <property name="targetObject" value="com.elift.component.scheduler.job.JobActiveAssociateMail" />
      <property name="targetMethod" value="run" />
    </bean>
    
    
    ----------------
    Java code
    
    	public class JobActiveAssociateMail {
    
    //	protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
    //		System.out.println("Scheduler started");
    //	
    //	}
    	public void run(){
    		System.out.println("Scheduler started");
    	}
    	
    }

  • #2
    Your definition is wrong. You have specified a targetObject with a value whereas it should be a ref or instead of a targetObject specify a targetClass.

    Code:
    <bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
      <property name="targetObject" value="com.elift.component.scheduler.job.JobActiveAssociateMail" />
      <property name="targetMethod" value="run" />
    </bean>

    Comment


    • #3
      Thanks for the reply
      i changed it to ref but still the error persists

      applicationcontext.xml looks like this
      Code:
      <bean id="javaJob" class="com.elift.component.scheduler.job.JobActiveAssociateMail"/>
      	
      <bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject"  ref="javaJob"/>
        <property name="targetMethod" value="run" />
      </bean>
      2007-05-29 19:41:16,567 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scheduler' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'cronProperties' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'cronProperties' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'jobDetail1' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobDetail1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: java.lang.String.run()
      Caused by:
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'cronProperties' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'jobDetail1' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobDetail1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: java.lang.String.run()
      Caused by:
      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobDetail1' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodException: java.lang.String.run()
      Caused by:
      java.lang.NoSuchMethodException: java.lang.String.run()
      at java.lang.Class.getMethod(Class.java:1581)

      Comment


      • #4
        Make sure that your configuration is being deployed and loaded correctly. Your configuration looks fine for as far as I can see.

        Comment


        • #5
          I am using tomcat to configure the scheduler.
          Apart from changing the web.xml file i think there is no extra configuration to run an application.

          My Jsp/HTML pages are coming up if i comment out the Context listener in the web.xml.

          And i am able to run the quartz on the standalone

          Comment


          • #6
            That seems like quite a strange error. Is it possible to see the rest of the quartz related configuration you are using?
            Last edited by karldmoore; Aug 30th, 2007, 06:00 AM.

            Comment


            • #7
              I believe that spring provides the quartz configuration in the xml itself.
              So i didn't do any extra settings.
              I configured in applicationcontext.xml only.
              applicationcontext.xml looks like this

              Code:
              <bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
              	<property name="jobDetail" ref="cronProperties" />
              	</bean>
              
              
              
              	<bean id="cronProperties" class="org.springframework.scheduling.quartz.CronTriggerBean">
              		<property name="jobDetail" ref="jobDetail1"/>
              		<property name="cronExpression" value="0/5 * * * * ?"/>
              	</bean>
              <bean id="javaJob" class="com.elift.component.scheduler.job.JobActiveAssociateMail"/>
              	
              <bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                <property name="targetObject"  ref="javaJob"/>
                <property name="targetMethod" value="run" />
              </bean>

              let me know if i missed anything in the configuration

              Comment


              • #8
                I'm not too sure about the SchedulerFactoryBean configuration, I think it should look like this.
                Code:
                <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                    <property name="triggers">
                        <list>
                            <ref bean="cronProperties" />
                        </list>
                    </property>
                </bean>
                I've just noticed that you talk about configuring Quartz through tomcat? Don't you just want to configure Quartz via the SchedulerFactoryBean?
                http://www.springframework.org/docs/...ctoryBean.html
                Last edited by karldmoore; Aug 30th, 2007, 06:00 AM.

                Comment


                • #9
                  As you said i added the list tag to the properties
                  and my applicationcontext looks like this. Different exception generated
                  Code:
                  	<bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                  	<property name="jobDetail"  />
                  		<property name="triggers">
                  			<list>
                  				<ref bean="cronProperties"/>
                  			</list>
                  		</property> 
                  	</bean>
                   
                  	<!-- Trigger for the job defined above -->
                  	<!-- Registered by the 'scheduler' bean -->
                  	<bean id="cronProperties" class="org.springframework.scheduling.quartz.CronTriggerBean">
                  		<property name="jobDetail" ref="jobMethod"/>
                  		<property name="cronExpression" value="0/5 * * * * ?"/>
                  	</bean>
                  <bean id="javaJob" class="com.elift.component.scheduler.job.JobActiveAssociateMail"/>
                  	
                  <bean id="jobMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                    <property name="targetObject"  ref="javaJob"/>
                    <property name="targetMethod" value="run" />
                  </bean>

                  2007-05-30 18:07:06,495 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
                  org.springframework.beans.factory.parsing.BeanDefi nitionParsingException: Configuration problem: Unexpected failure during bean definition parsing
                  Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]
                  Bean 'scheduler'; nested exception is org.springframework.beans.factory.parsing.BeanDefi nitionParsingException: Configuration problem: <property> element for property 'jobDetail' must specify a ref or value
                  Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]
                  Bean 'scheduler'
                  -> Property 'jobDetail'
                  Caused by:
                  org.springframework.beans.factory.parsing.BeanDefi nitionParsingException: Configuration problem: <property> element for property 'jobDetail' must specify a ref or value
                  Offending resource: ServletContext resource [/WEB-INF/applicationContext.xml]
                  Bean 'scheduler'
                  -> Property 'jobDetail'
                  at org.springframework.beans.factory.parsing.FailFast ProblemReporter.error(FailFastProblemRepo

                  Comment


                  • #10
                    You've not copied the example exactly though.
                    Code:
                    	<bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                    	<property name="jobDetail"  />
                    		<property name="triggers">
                    			<list>
                    				<ref bean="cronProperties"/>
                    			</list>
                    		</property> 
                    	</bean>
                    Code:
                    	<bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                    		<property name="triggers">
                    			<list>
                    				<ref bean="cronProperties"/>
                    			</list>
                    		</property> 
                    	</bean>
                    Last edited by karldmoore; Aug 30th, 2007, 05:59 AM.

                    Comment


                    • #11
                      The javadoc for the method setJobDetails in org.springframework.scheduling.quartz.SchedulerFac toryBean states that you do not have to set this in the scheduler if your trigger determines the job detail itself (as your configuration does).

                      Another thing that is kind of strange is the setter method is setJobDetails and you had jobDetail declared in your configuration for the scheduler. I would have expected another error stating that jobDetail could not be found? Maybe it is somewhere else in the log?

                      Comment


                      • #12
                        Soory that i pasted wrong code in the forum.
                        I modified the properties new error as flows.

                        2007-05-31 09:21:53,184 ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
                        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scheduler' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'cronProperties' while setting bean property 'triggers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'cronProperties' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'jobMethod' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobMethod' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.collections.SetUtils.orderedSet (Ljava/util/SetLjava/util/Set;
                        Caused by:
                        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'cronProperties' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'jobMethod' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobMethod' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.collections.SetUtils.orderedSet (Ljava/util/SetLjava/util/Set;
                        Caused by:
                        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'jobMethod' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.apache.commons.collections.SetUtils.orderedSet (Ljava/util/SetLjava/util/Set;
                        Caused by:
                        java.lang.NoSuchMethodError: org.apache.commons.collections.SetUtils.orderedSet (Ljava/util/SetLjava/util/Set;
                        at org.quartz.JobDetail.<init>(JobDetail.java:85)


                        Code:
                        	<bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                        		<property name="triggers">
                        			<list>
                        				<ref bean="cronProperties"/>
                        			</list>
                        		</property> 
                        	</bean>
                        Code:
                        	<bean id="cronProperties" class="org.springframework.scheduling.quartz.CronTriggerBean">
                        		<property name="jobDetail" ref="jobMethod"/>
                        		<property name="cronExpression" value="0/5 * * * * ?"/>
                        	</bean>
                        Code:
                        <bean id="javaJob" class="com.elift.component.scheduler.job.JobActiveAssociateMail"/>
                        	
                        <bean id="jobMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
                          <property name="targetObject"  ref="javaJob"/>
                          <property name="targetMethod" value="run" />
                        </bean>

                        java code

                        Code:
                        public class JobActiveAssociateMail { //extends QuartzJobBean
                        
                        //	protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
                        //		System.out.println("Scheduler started");
                        //	
                        //	}
                        	public void run(){
                        		System.out.println("Scheduler started");
                        	}
                        	
                        }

                        Comment


                        • #13
                          Hi,

                          It seem that u r using some old libs. like common-collections.jar. Update ur jars from Spring latest version.

                          Shahzad

                          Comment


                          • #14
                            Originally posted by rpoetker View Post
                            Another thing that is kind of strange is the setter method is setJobDetails and you had jobDetail declared in your configuration for the scheduler. I would have expected another error stating that jobDetail could not be found? Maybe it is somewhere else in the log?
                            I guess this might be because it fails fast when parsing as the document is badly formed.
                            Last edited by karldmoore; Aug 30th, 2007, 05:59 AM.

                            Comment


                            • #15
                              Thanks for all your inputs. shahzad.ahsan solved my problem.
                              Therewas jars version mismatch.
                              Now scheduler is up .
                              Thanks once again

                              Comment

                              Working...
                              X