Announcement Announcement Module
Collapse
No announcement yet.
running quartz scheduler in j2ee container (OC4J) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • running quartz scheduler in j2ee container (OC4J)

    I like to schedule jobs that should run in OC4J j2ee container.

    I was looking at the spring-reference.pdf.

    It does not tell how to package it.
    Should I be making a WAR or EAR file.
    Is there any simple sample which I can use.
    Does any body uses spring frmae work in Oracle OC4j conatiner

  • #2
    Is there any simple sample which I can use.
    take a look at imagedb sample from Spring distribution.

    HTH.

    Comment


    • #3
      Is there any thing missing
      here is my web.xml

      <web-app>
      <description>Empty web.xml file for Web Application</description>
      <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/schedulingContext-quartz.xml</param-value>
      </context-param >
      <session-config>
      <session-timeout>35</session-timeout>
      </session-config>
      <mime-mapping>
      <extension>html</extension>
      <mime-type>text/html</mime-type>
      </mime-mapping>
      <mime-mapping>
      <extension>txt</extension>
      <mime-type>text/plain</mime-type>
      </mime-mapping>
      </web-app>

      schedulingcontext-quartz.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
      <!--
      - Scheduler context for Quartz. Schedules jobs.
      -->
      <beans>
      <!-- Quartz Scheduler, with pre-registered triggers -->
      <!-- Will automatically start scheduling on context startup -->
      <bean id="scheduler" class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
      <property name="autoStartup"><value>true</value></property>
      <property name="applicationContextSchedulerContextKey"><valu e>applicationContext</value></property>
      <property name="waitForJobsToCompleteOnShutdown"><value>true </value></property>
      <property name="quartzProperties">
      <props>
      <!-- ThreadPool -->
      <prop key="org.quartz.threadPool.class">org.quartz.simpl .SimpleThreadPool</prop>
      <prop key="org.quartz.threadPool.threadCount">5</prop>
      <prop key="org.quartz.threadPool.threadPriority">5</prop>
      </props>
      <property name="triggers">
      <list>
      <ref local="SimpleJobTrigger"/>
      <ref local="CronJobTrigger"/>
      </list>
      </property>
      </bean>
      <!-- Job definition for ProvisionJobScheduler -->
      <bean id="ProvisionJobScheduler" class="org.springframework.scheduling.quartz.JobDe tailBean">
      <property name="jobClass">
      <value>com.talk.provisioning.scheduling.ProvisionJ obScheduler</value>
      </property>
      </bean>

      <!-- Trigger for the job defined above -->
      <!-- Registered by the 'scheduler' bean -->

      <bean id="SimpleJobTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
      <property name="jobDetail"><ref bean="ProvisionJobScheduler"/></property>
      <property name="startDelay"><value>10000</value></property>
      <property name="repeatInterval"><value>10000</value></property>
      </bean>


      <bean id="featureQualifyJobDetail" class="org.springframework.scheduling.quartz.Metho dInvokingJobDetailFactoryBean">
      <property name="targetObject"><ref bean="FeatureQualify"/></property>
      <property name="targetMethod"><value>CallMe</value></property>
      </bean>

      <!-- Trigger for the job defined above -->
      <!-- Registered by the 'scheduler' bean -->
      <bean id="CronJobTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
      <property name="jobDetail"><ref bean="featureQualifyJobDetail"/></property>
      <property name="cronExpression"><value>0 0/30 * * * ?</value></property>
      </bean>
      </beans>


      here is my class ProvisionJobScheduler
      package com.talk.provisioning.scheduling;

      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;

      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;

      import org.springframework.scheduling.quartz.QuartzJobBea n;

      /**
      *
      *
      */
      public class ProvisionJobScheduler extends QuartzJobBean
      {
      private Log logger = null;

      public ProvisionJobScheduler()
      {
      logger = LogFactory.getLog(getClass());
      }

      protected void executeInternal(JobExecutionContext context) throws JobExecutionException
      {
      logger.info("I schedule by cron trigger, scheduled by Quartz");
      System.out.println("I schedule by cron trigger, scheduled by Quartz");


      logger.info("Next job execution at: " + context.getNextFireTime());
      System.out.println("Next job execution at: " + context.getNextFireTime());
      }
      }

      when I create a WAR file the structure looks like
      scheduler
      |_______WEB-INF
      |_______Classes
      | |____{package}
      |_______Lib
      | |_{all libraries}
      |_schedulingcontext-quartz.xml
      |_web.xml

      but when I deploy on server(OC4J) I don't see any output.
      AM I MISSING ?
      HELP IS APPERICATED.

      Comment


      • #4
        add the following to your web.xml
        Code:
        	<servlet>
        		<servlet-name>context</servlet-name>
        		<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
        		<load-on-startup>1</load-on-startup>
        	</servlet>
        HTH

        Comment


        • #5
          thanks for the input,
          after adding ths missing info.
          I deployed on OC4J and I am getting this errors:
          I am using inform. as posted above.

          Oct 11, 2004 4:33:46 PM org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
          INFO: Loading XML bean definitions from resource [/WEB-INF/schedulingContext-quartz.xml] of ServletContext
          Oct 11, 2004 4:33:47 PM org.springframework.context.support.AbstractXmlApp licationContext refreshBeanFactory
          INFO: Bean factory for application context [Root XmlWebApplicationContext]: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [
          scheduler,ProvisionJobScheduler,SimpleJobTrigger,f eatureQualifyJobDetail,CronJobTrigger]; Root of BeanFactory hierarchy
          Oct 11, 2004 4:33:47 PM org.springframework.context.support.AbstractApplic ationContext refresh
          INFO: 5 beans defined in ApplicationContext [Root XmlWebApplicationContext]
          Oct 11, 2004 4:33:47 PM org.springframework.context.support.AbstractApplic ationContext initMessageSource
          INFO: No MessageSource found for context [Root XmlWebApplicationContext]: using empty default
          Oct 11, 2004 4:33:47 PM org.springframework.context.support.AbstractApplic ationContext initApplicationEventMulticaster
          INFO: No ApplicationEventMulticaster found for context [Root XmlWebApplicationContext]: using default
          Oct 11, 2004 4:33:47 PM org.springframework.ui.context.support.UiApplicati onContextUtils initThemeSource
          INFO: No ThemeSource found for [Root XmlWebApplicationContext]: using ResourceBundleThemeSource
          Oct 11, 2004 4:33:47 PM org.springframework.context.support.AbstractApplic ationContext refreshListeners
          INFO: Refreshing listeners
          Oct 11, 2004 4:33:47 PM org.springframework.beans.factory.support.DefaultL istableBeanFactory preInstantiateSingletons
          INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [scheduler,ProvisionJobSchedul
          er,SimpleJobTrigger,featureQualifyJobDetail,CronJo bTrigger]; Root of BeanFactory hierarchy]
          Oct 11, 2004 4:33:47 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
          INFO: Creating shared instance of singleton bean 'scheduler'
          Oct 11, 2004 4:33:48 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
          INFO: Creating shared instance of singleton bean 'SimpleJobTrigger'
          Oct 11, 2004 4:33:48 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
          INFO: Creating shared instance of singleton bean 'ProvisionJobScheduler'
          Oct 11, 2004 4:33:48 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
          INFO: Creating shared instance of singleton bean 'CronJobTrigger'
          Oct 11, 2004 4:33:48 PM org.springframework.beans.factory.support.Abstract BeanFactory getBean
          INFO: Creating shared instance of singleton bean 'featureQualifyJobDetail'
          Oct 11, 2004 4:33:48 PM org.springframework.beans.factory.support.Abstract BeanFactory destroySingletons
          INFO: Destroying singletons in factory {org.springframework.beans.factory.support.Default ListableBeanFactory defining beans [scheduler,ProvisionJobScheduler,Simp
          leJobTrigger,featureQualifyJobDetail,CronJobTrigge r]; Root of BeanFactory hierarchy}
          Oct 11, 2004 4:33:48 PM org.springframework.web.context.ContextLoader initWebApplicationContext
          SEVERE: Context initialization failed
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'scheduler' defined in resource [/WEB-INF/schedulingContext-quartz.xml] of
          ServletContext: Can't resolve reference to bean 'CronJobTrigger' while setting property 'triggers[1]'; nested exception is org.springframework.beans.factory.Bea
          nCreationException: Error creating bean with name 'CronJobTrigger' defined in resource [/WEB-INF/schedulingContext-quartz.xml] of ServletContext: Can't resolve r
          eference to bean 'featureQualifyJobDetail' while setting property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error
          creating bean with name 'featureQualifyJobDetail' defined in resource [/WEB-INF/schedulingContext-quartz.xml] of ServletContext: Can't resolve reference to bean
          'FeatureQualify' while setting property 'targetObject'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'Feat
          ureQualify' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [scheduler,ProvisionJobScheduler,SimpleJobTrigger,f ea
          tureQualifyJobDetail,CronJobTrigger]; Root of BeanFactory hierarchy
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'CronJobTrigger' defined in resource [/WEB-INF/schedulingContext-quartz.xm
          l] of ServletContext: Can't resolve reference to bean 'featureQualifyJobDetail' while setting property 'jobDetail'; nested exception is org.springframework.beans
          .factory.BeanCreationException: Error creating bean with name 'featureQualifyJobDetail' defined in resource [/WEB-INF/schedulingContext-quartz.xml] of ServletCon
          text: Can't resolve reference to bean 'FeatureQualify' while setting property 'targetObject'; nested exception is org.springframework.beans.factory.NoSuchBeanDef
          initionException: No bean named 'FeatureQualify' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defining beans [scheduler,Provi
          sionJobScheduler,SimpleJobTrigger,featureQualifyJo bDetail,CronJobTrigger]; Root of BeanFactory hierarchy
          org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'featureQualifyJobDetail' defined in resource [/WEB-INF/schedulingContext-
          quartz.xml] of ServletContext: Can't resolve reference to bean 'FeatureQualify' while setting property 'targetObject'; nested exception is org.springframework.be
          ans.factory.NoSuchBeanDefinitionException: No bean named 'FeatureQualify' is defined: org.springframework.beans.factory.support.DefaultL istableBeanFactory defini
          ng beans [scheduler,ProvisionJobScheduler,SimpleJobTrigger,f eatureQualifyJobDetail,CronJobTrigger]; Root of BeanFactory hierarchy
          org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'FeatureQualify' is defined: org.springframework.beans.factory.support.DefaultL ist
          ableBeanFactory defining beans [scheduler,ProvisionJobScheduler,SimpleJobTrigger,f eatureQualifyJobDetail,CronJobTrigger]; Root of BeanFactory hierarchy
          at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:291)

          Comment


          • #6
            Spring is complaining about not beeing able to find bean FeatureQualify. Where are you defining that bean?

            Comment


            • #7
              Omar,
              Thanks for pointing out the error. I was able schedule both cron and simple triggers jobs.

              again your quick response was highly appreciated.

              Comment


              • #8
                Error in the schedulingcontext-quartz.xml &amp; directory structure ...

                Just a few minor errors :
                Code:
                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
                <!--
                	- Scheduler context for Quartz. Schedules jobs.
                -->
                <beans>
                	<!-- Quartz Scheduler, with pre-registered triggers -->
                	<!-- Will automatically start scheduling on context startup -->
                	<bean id="scheduler" class="org.springframework.scheduling.quartz.Sched ulerFactoryBean">
                		<property name="autoStartup">
                			<value>true</value>
                		</property>
                		<property name="applicationContextSchedulerContextKey">
                			<value>applicationContext</value>
                		</property>
                		<property name="waitForJobsToCompleteOnShutdown">
                			<value>true</value>
                		</property>
                		<property name="quartzProperties">
                			<props>
                				<!-- ThreadPool -->
                				<prop key="org.quartz.threadPool.class">org.quartz.simpl .SimpleThreadPool</prop>
                				<prop key="org.quartz.threadPool.threadCount">5</prop>
                				<prop key="org.quartz.threadPool.threadPriority">5</prop>
                			</props>
                			<property name="triggers">
                				<list>
                					<ref local="SimpleJobTrigger" />
                					<ref local="CronJobTrigger" />
                				</list>
                		<!-- ERROR here -->
                		</property>
                	</bean>
                	<!-- Job definition for ProvisionJobScheduler -->
                	<bean id="ProvisionJobScheduler" class="org.springframework.scheduling.quartz.JobDe tailBean">
                		<property name="jobClass">
                			<value>com.talk.provisioning.scheduling.ProvisionJ obScheduler</value>
                		</property>
                	</bean>
                
                	<!-- Trigger for the job defined above -->
                	<!-- Registered by the 'scheduler' bean -->
                
                	<bean id="SimpleJobTrigger" class="org.springframework.scheduling.quartz.Simpl eTriggerBean">
                		<property name="jobDetail">
                			<ref bean="ProvisionJobScheduler" />
                		</property>
                		<property name="startDelay">
                			<value>10000</value>
                		</property>
                		<property name="repeatInterval">
                			<value>10000</value>
                		</property>
                	</bean>
                
                
                	<bean id="featureQualifyJobDetail" class="org.springframework.scheduling.quartz.Metho dInvokingJobDetailFactoryBean">
                		<property name="targetObject">
                			<ref bean="FeatureQualify" />
                		</property>
                		<property name="targetMethod">
                			<value>CallMe</value>
                		</property>
                	</bean>
                
                	<!-- Trigger for the job defined above -->
                	<!-- Registered by the 'scheduler' bean -->
                	<bean id="CronJobTrigger" class="org.springframework.scheduling.quartz.CronT riggerBean">
                		<property name="jobDetail">
                			<ref bean="featureQualifyJobDetail" />
                		</property>
                		<property name="cronExpression">
                			<value>0 0/30 * * * ?</value>
                		</property>
                	</bean>
                </beans>
                Another point, is that I believe the directory structure is as follows :
                Code:
                .
                |-- META-INF
                |   `-- MANIFEST.MF
                |-- WEB-INF
                |   |-- classes
                |   |   `-- com
                |   |       `-- a3system
                |   |           `-- jobs
                |   |               |-- ProvisionJobScheduler.class
                |   |               `-- TestJobs.class
                |   |-- lib
                |   |   |-- commons-collections.jar
                |   |   |-- log4j-1.2.14.jar
                |   |   |-- quartz-1.6.0.jar
                |   |   `-- spring.jar
                |   |-- schedulingcontext-quartz.xml
                |   `-- web.xml
                `-- index.jsp
                Am I correct or ... ?

                My only worry is now an error at start up :
                Code:
                06:39:46,083 INFO  [DefaultListableBeanFactory] Destroying singletons in {org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [scheduler,ProvisionJobScheduler,SimpleJobTrigger,featureQualifyJobDetail,CronJobTrigger]; root of BeanFactory hierarchy}
                06:39:46,083 ERROR [ContextLoader] Context initialization failed
                org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduler' defined in ServletContext resource [/WEB-INF/schedulingcontext-quartz.xml]: Cannot resolve reference to bean 'CronJobTrigger' while setting bean property 'triggers' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CronJobTrigger' defined in ServletContext resource [/WEB-INF/schedulingcontext-quartz.xml]: Cannot resolve reference to bean 'featureQualifyJobDetail' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'featureQualifyJobDetail' defined in ServletContext resource [/WEB-INF/schedulingcontext-quartz.xml]: Cannot resolve reference to bean 'FeatureQualify' while setting bean property 'targetObject'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'FeatureQualify' is defined
                Caused by: 
                org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CronJobTrigger' defined in ServletContext resource [/WEB-INF/schedulingcontext-quartz.xml]: Cannot resolve reference to bean 'featureQualifyJobDetail' while setting bean property 'jobDetail'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'featureQualifyJobDetail' defined in ServletContext resource [/WEB-INF/schedulingcontext-quartz.xml]: Cannot resolve reference to bean 'FeatureQualify' while setting bean property 'targetObject'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'FeatureQualify' is defined
                Caused by: 
                org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'featureQualifyJobDetail' defined in ServletContext resource [/WEB-INF/schedulingcontext-quartz.xml]: Cannot resolve reference to bean 'FeatureQualify' while setting bean property 'targetObject'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'FeatureQualify' is defined
                Caused by: 
                org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'FeatureQualify' is defined
                	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:338)
                \T,
                Last edited by tsmets; Dec 4th, 2006, 11:49 PM. Reason: A few typo's myself + question about missing bean

                Comment


                • #9
                  I would presume this is because featureQualifyJobDetail has a reference to FeatureQualify but that bean isn't in the applicationContext you pasted.

                  Code:
                   <bean id="featureQualifyJobDetail" class="org.springframework.scheduling.quartz.Metho dInvokingJobDetailFactoryBean">
                  		<property name="targetObject">
                  			<ref bean="FeatureQualify" />
                  		</property>
                  		<property name="targetMethod">
                  			<value>CallMe</value>
                  		</property>
                  	</bean>

                  Comment


                  • #10
                    Missing bean

                    Sure but it is mentionned nowhere in the example
                    I got the exmaple running on my machine but with the CronJob example ... !

                    \T,

                    Comment


                    • #11
                      Well thats easy enough to fix. Add a bean called FeatureQualify, add a class for this bean and ensure the class has a method called CallMe.

                      Code:
                      <bean id="FeatureQualify" class="com.blah.FeatureQualifyBean"></bean>
                       
                      public class FeatureQualifyBean {
                          public void CallMe() {
                              System.out.println("you've been called");
                          }
                      }

                      Comment

                      Working...
                      X