Spring + Quartz Configuration instance

Source: Internet
Author: User

Spring provides a convenient Factorybean class for creating quartz scheduler, trigger, and jobdetail so that the benefits of injection can be enjoyed in the spring container. In addition, Spring provides some handy tool classes that directly package the beans in spring into legitimate tasks. Spring further reduces the difficulty of using quartz and can use quartz in a more spring-style manner. In summary, it provides support in two ways:
1) Provide a more bean-style extension class for the important component classes of quartz;
2) provides the Beanfactory class for creating scheduler, which facilitates the creation of corresponding component objects in the spring environment and the action of starting and stopping with the spring container life cycle.
Configuration file:

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" ><beans > <!--the work class to invoke-<bean id= "quartzjob" class= "test. Task ></bean> <!--define methods for calling objects and calling objects--<bean id= "Jobtask" class= "Org.springframework.schedul            Ing.quartz.MethodInvokingJobDetailFactoryBean "> <!--called Class-<property name=" TargetObject "> <ref bean= "Quartzjob"/> </property> <!--calling methods in class--<property name= "Targetmethod" > <value>work</value> </property> </bean> <!--define trigger time --<bean id= "Dotime" class= "Org.springframework.scheduling.quartz.CronTriggerBean" > <propert        Y name= "Jobdetail" > <ref bean= "jobtask"/> </property> <!--cron expression-- <property name= "Cronexpression"> <value>10,15,20,25,30,35,40,45,50,55 * * * * *?</value> </property> </bean&    Gt        <!--general Management class if lazy-init= ' false ' then the container starts executing the scheduler--<bean id= "Startquertz" lazy-init= "false" autowire= "no"            class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" > <property name= "triggers" > <list> <ref bean= "Dotime"/> </list> </property> &LT;/BEAN&G T;</beans>

Work class to dispatch:

public class task{public    void work () {        System.out.println ("Quartz Task Scheduler! ");    }}

Main test file:

public class Quartztest {public    static void Main (string[] args) {        System.out.println ("Test start.");        ApplicationContext context = new Classpathxmlapplicationcontext ("Applicationcontext.xml");        If you set the Startquertz Bean's lazy-init to false in the configuration file, you do not instantiate        System.out.print ("Test End: \ n ");}    }

Reference article "http://www.cnblogs.com/kay/archive/2007/11/02/947372.html"
"Http://www.diybl.com/course/3_program/java/javajs/2008530/118164.html"

Spring + Quartz Configuration instance

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.