Spring 4.3.5 Configuring Quartz 2.2.1 Task scheduling problems and workarounds

Source: Internet
Author: User
Tags xmlns

Spring Version: 4.3.5.RELEASE

Quartz version: 2.2.1

1. Basic Configuration

(1) Configure your own Write task class XML code <bean id= "Testtimer" class= "Org.linkscholar.biz.timer.TestTimer"/>

(2) Configuring Jobdetail XML code <bean id= "Testjobdetail" class= "Org.springframework.scheduling.quartz.MethodInvokingJo           Bdetailfactorybean "> <property name=" targetObject "> <ref bean=" Testtimer "/>           </property> <property name= "Targetmethod" > <value>scan</value> </property> </bean>

TARGETOBJECT Specifies the Task object, Targetmethod specifies the object execution method

(3) Configure trigger XML code <bean id= "Testcrontrigger" class= "Org.springframework.scheduling.quartz.CronTriggerBean" >           <property name= "Jobdetail" > <ref bean= "testjobdetail"/> </property>       <property name= "Cronexpression" > <value>0 0/1 * * *?</value> </property> </bean>

Here 0 0/1 * * *. Indicates that every minute is executed, and the specific configuration of the call time can be referenced

Http://jingyan.baidu.com/article/0f5fb099cc244d6d8234ea6b.html

(4) Configuring the Total Management class XML code <bean class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init= "false" >               <property name= "triggers" > <list> <ref local= "Testcrontrigger"/> </list> </property> </bean>

Lazy-init= "False" indicates that the container starts execution of the dispatch task, where multiple triggers can be configured to be managed uniformly

2. Problems that Arise

Following the above configuration, the JUnit test run was written and an error was found:

(1)

Cannot find class [Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean] for beans with name

The exception is that the class above cannot be found, I went to Spring-context.jar to find, although there is org.springframework.scheduling this package, but there is no quartz, and later on the internet for a long time to know, above this class in Spring-contex-support this package (formerly Spring uses a jar, which is then split into multiple jar packages, and it's the right one to bring in.

As shown below (Pom.xml)


<dependency>
      <groupId>org.springframework</groupId>
    <artifactId> spring-context-support</artifactid>
     <version>4.3.5.RELEASE</version>
</dependency >

<dependency>  
   <groupid>org.quartz-scheduler</gro upid>
   <artifactid>quartz</ artifactid>  
   <version>2.2.1</version>
</dependency>
<dependency>


(2)

After resolving the above problem, a new error appears:

Java.lang.IncompatibleClassChangeError:class Org.springframework.scheduling.quartz.CronTriggerBean has interface Org.quartz.CronTrigger as Super class

This is due to version incompatibility, the solution is:

1. Reduce quartz to 1.x version

2. Replace the original Xxxtriggerbean with Xxxtriggerfactorybean as suggested by spring. This is the third step in the configuration trigger class Crontriggerbean replaced with crontriggerfactorybean:xml code <bean id= "Testcrontrigger" class= "               Org.springframework.scheduling.quartz.CronTriggerFactoryBean "> <property name=" Jobdetail ">               <ref bean= "Testjobdetail"/> </property> <property name= "Cronexpression" > <value>0 0/1 * * *?</value> </property> </bean>

The complete quartz XML code is referenced below

<?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:context="/HTTP/ Www.springframework.org/schema/context "xmlns:jdbc=" Http://www.springframework.org/schema/jdbc "xmlns:jee=" http ://www.springframework.org/schema/jee "xmlns:tx=" Http://www.springframework.org/schema/tx "xmlns:util="/HTTP/ Www.springframework.org/schema/util "xsi:schemalocation=" Http://www.springframework.org/schema/beans http://www. Springframework.org/schema/beans/spring-beans-4.0.xsd Http://www.springframework.org/schema/context/HTTP Www.springframework.org/schema/context/spring-context-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/JDBC/HTTP Www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd Http://www.springframework.org/schema/jee/HTTP Www.springframework.org/schema/jee/spring-jee-4.0.xsd Http://www.springframewo 

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.