Configuration of quartz in spring

Source: Internet
Author: User

Quartz is a powerful enterprise-level task scheduling framework that inherits and simplifies quartz in spring, and looks at how quartz is configured in spring:

First, write a test-dispatched class: (Quartzhelloworldjob.java)

 Package Com.jp.quartz;  Public class quartzhelloworldjob {     publicvoid  dotask ()     {     System.out.println ( "------HelloWorld Task Scheduler!!! ");     } }


Spring 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-<BeanId= "Quartzjob"Class= "Com.jp.quartz.QuartzHelloWorldJob"></Bean><!--Define methods for calling and invoking objects-<BeanId= "Jobtask"Class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"><!--The class that is called-<PropertyName= "TargetObject"><RefBean= "Quartzjob"/></Property><!--Calling methods in a class-<PropertyName= "Targetmethod"><Value>dotask</Value></Property></Bean><!--Define Trigger Time-<BeanId= "Dotime"Class= "Org.springframework.scheduling.quartz.CronTriggerFactoryBean"><PropertyName= "Jobdetail"><RefBean= "Jobtask"/></Property><!--Cron-expression-<PropertyName= "Cronexpression"><!--0:15 per day execution of procedures-<Value>0 15 0 * *?</Value></Property></Bean><!--General Management Class if you lazy-init= ' false ' then the container starts executing the scheduler-<BeanId= "Startquertz"Lazy-init= "false"Autowire= "No"Class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean"><Propertyname= "triggers" > Span style= "color: #0000ff;" ><list> << Span style= "color: #800000;" >ref bean= "Dotime" / > </list> Span style= "color: #0000ff;" ></property> bean> </< Span style= "color: #800000;" >beans>           

Test procedure:

 PackageCom.jp.quartz;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.context.support.ClassPathXmlApplicationContext; Public classmaintest{/**      * @paramargs*/      Public Static voidMain (string[] args) {ApplicationContext context=NewClasspathxmlapplicationcontext ("Spring-quartz-config.xml"); //if the Startquertz Bean's lazy-init is set to False in the configuration file, it will not be instantiated//Context.getbean ("Startquertz");     } }

Finally, put the log4j.properties in the SRC directory, start the main class can be tested.

About cron expressions (from the network):

The Cron expression consists of the following 7 fields:

    • Seconds
    • Score of
    • Hours
    • Date within the month
    • Month
    • Week Date
    • Year (optional field)

  

Configuration of quartz in spring

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.