Spring+quartz Timer use

Source: Internet
Author: User

Project use:spring+springmvc+jpa+maven

1. referencing in Pom.xml Quartz of the Jar Package

<!--quartz--><dependency> <groupId>org.quartz-scheduler</groupId> <artifactId> Quartz</artifactid> <version>2.2.1</version></dependency>

Quartz need Spring-context-support-3.2.4.release.jar etc (quartz2.x version required spring3.1 above version support, specific please Baidu)


2. Task class (does not inherit the job interface)

Package Com.test.utils.quartz;import Java.io.ioexception;import Java.io.inputstream;import java.util.Properties; Import javax.annotation.resource;import com.test.service.order.iorderservice;/** * Quartz Timer-Order * * @author cc * */publi C class Quartzjoboforder {//Service@resource (name = "Testservice") private itestservice testservice;public void work () {/ /do something. You can use the service, DAO Layer Method}}


3. Add Quartz configuration to spring configuration file

        <!--  Work class to invoke  --><bean id= "Quartzjob_1"  class= "Com.test.utils.quartz.QuartzJobOfOrder" ></bean><!--  defining methods for calling objects and calling objects  --> <bean id= "Jobtask_1"  class= " Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean "><!--  called classes  -->< Property name= "TargetObject" ><ref bean= "quartzjob_1"  /></property><!--  Calling a method in a class  --><property name= "Targetmethod" ><value>work</value></property> </bean><!--  Define trigger time  --><bean id= "crontrigger_1"  class= " Org.springframework.scheduling.quartz.CronTriggerFactoryBean "><property name=" Jobdetail "><ref  bean= "Jobtask_1"  /></property><!-- 0 0 23 L * ?  The last day of the month between 23 points  ;0/10 * * * * ?  every 10 seconds to execute  --><property name= "CroNexpression "><value>0 0 23 L * ?</value></property></bean> <!--  General management   If you 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= "crontrigger_1"  /></list></ Property></bean>


With the above configuration, you can use the quartz timer.

There is no way to use annotations, there is time to get it.

Spring+quartz Timer use

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.