Spring-3.2.4 + Quartz-2.2.0 Integration Instance _ Timing task scheduling

Source: Internet
Author: User
SPRING3.0 does not support Quartz2.0 because Org.quartz.CronTrigger in 2.0 has changed from class to a interface to cause Incompatibleclasschangeerror errors:
caused By:java.lang.IncompatibleClassChangeError:class Org.springframework.scheduling.quartz.CronTriggerBean has Interface Org.quartz.CronTrigger as Super class

Today, I just downloaded Spring3.2.4 and found that this new version has already supported quartz2.x. Previous spring versions only support quartz-1.8.x and previous versions, and share them in small instances.


Note: Crontriggerfactorybean is used to integrate quartz2.x in the Spring3.2.4 configuration file, and Crontriggerbean is used to integrate quartz1.8.x and previous versions.


Code structure and reference jar see the following figure:

Applicationcontext.xml:

[html]  View Plain Copy <?xml version= "1.0"  encoding= "UTF-8"?>   <beans  xmlns= "Http://www.springframework.org/schema/beans"        xmlns:xsi= "http:// Www.w3.org/2001/XMLSchema-instance " xmlns:p=" http://www.springframework.org/schema/p "        xsi:schemalocation= "http://www.springframework.org/schema/beans         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">           <!--  Startup trigger configuration start  -->       <bean  name= "Startquertz"  lazy-init= "false"  autowire= "no"             class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >            <property name= "triggers" >                <list>                    <ref bean= "Myjobtrigger"  />                </list>            </property>       </bean>        <!--  Start trigger configuration end  -->          <!--   Scheduling configuration start  -->       <!--            quartz-1.8 Previous configuration         <bean id= "Myjobtrigger"            class= " Org.springframework.scheduling.quartz.CronTriggerBean ">            <property name= "Jobdetail" > &nbsp             <ref bean= "MyJobDetail"  / >           </property>            <property name= "Cronexpression" >                <value>0/1 * * * * ?</ value>           </property>        </bean>       -->       <!--  quartz-2.x configuration  -->       <bean id= "Myjobtrigger"            class= " Org.springframework.scheduling.quartz.CronTriggerFactoryBean ">            <property name= "Jobdetail" &GT;&Nbsp;              <ref bean= " Myjobdetail " />           </property>            <property name= "Cronexpression" >               <value>0/1 * * *  * ?</value>           </property>        </bean>       <!--  Dispatch configuration End  -->          <!-- job configuration start  -->       <bean id= "Myjobdetail"             class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >          &nBsp; <property name= "TargetObject" >                <ref bean= "Myjob"  />            </property>           <property  name= "Targetmethod" >                <value>work</value>           </property >       </bean>       <!-- job End of configuration  -->          <!--  work bean -->        <bean id= "Myjob"  class= "Com.tgb.lk.demo.quartz.MyJob"  />      </beans>  

Myjob.java:

[Java] View plain copy import java.util.Date;       public class Myjob {public void work () {System.out.println ("date:" + new Date (). toString ()); }   }

Xml:

[html]  View Plain Copy <?xml version= "1.0"  encoding= "UTF-8"?>   <web-app  version= "2.5"  xmlns= "Http://java.sun.com/xml/ns/javaee"        xmlns:xsi= " Http://www.w3.org/2001/XMLSchema-instance "       xsi:schemalocation=" http:// java.sun.com/xml/ns/javaee        http://java.sun.com/xml/ns/javaee/web-app_ 2_5.xsd ">              <!-- Spring  config start -->       <context-param>            <param-name>contextConfigLocation</param-name>           <param-value>/WEB-INF/classes/applicationContext.xml< /param-value>       </context-param>           <listener>           <listener-class> org.springframework.web.context.contextloaderlistener</listener-class>        </listener>       <!-- spring config end -- >          <welcome-file-list>            <welcome-file>index.jsp</welcome-file>        </welcome-file-list>   </web-app>  

Code Download Address: http://download.csdn.net/detail/lk_blog/6277021

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.