Springqtz Time Task Scheduling

Source: Internet
Author: User

1. Configure the required MAVEN jar package

<!--Task Scheduler requires a JAR--
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.2.4.RELEASE</version>
</dependency>
<!--Task Scheduler requires a JAR--

2. configuration file Spring-timer.xml

<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE beans Public "-//spring//dtd bean//en" "Http://www.springframework.org/dtd/spring-beans.dtd" >
<beans>
<!--Configure the Scheduler quartz, where Jobdetail is configured in two ways-
<!--method One: Using Jobdetailbean, the task class must implement the job interface--
<!--<bean id= "Myjob" class= "Org.springframework.scheduling.quartz.JobDetailBean" >-
<!--<property name= "name" value= "Examplejob" ></property>-
<!--<property name= "Jobclass" value= "Com.zbb.cn.filter.SpringQtz" ></property>-
<!--<property name= "Jobdataasmap" >-
<!--<map>--
<!--<entry key= "Service" >-
<!--<value>simple is the beat</value>-
<!--</entry>--
<!--</map>--
<!--</property>--
<!--</bean>--
<!--run, please comment out the way! -
<!--
Mode two: Using Methodinvokingjobdetailfactorybean, the task class can not implement the job interface, through the Targetmethod to specify the calling method
-
<!--define methods in target beans and beans---
<bean id= "Springqtzjob" class= "Com.cc.hkjc.controller.backstage.interceptor.SpringQtz" >

</bean>

<bean id= "Springqtzjobmethod"
class= "Org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" >
<property name= "TargetObject" >
<ref bean= "Springqtzjob"/>
</property>
<property name= "Targetmethod" > <!--the method name to execute--
<value>execute</value>
</property>
</bean>

<!--======================== Dispatch trigger ========================--
<bean id= "Crontriggerbean" class= "Org.springframework.scheduling.quartz.CronTriggerBean" >
<property name= "Jobdetail" ref= "Springqtzjobmethod" ></property>
<!--<property name= "cronexpression" value= "0/5 * * * *?" ></property>
<property name= "cronexpression" value= "0 0 10 * *?" ></property> <!--triggered every night 10 o'clock
</bean>

<!--======================== Dispatch factory ========================--
<bean id= "Springjobschedulerfactorybean"
class= "Org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name= "Triggers" >
<list>
<ref bean= "Crontriggerbean"/>
</list>
</property>
</bean>

</beans>

Package com.cc.hkjc.controller.backstage.interceptor;

Import Java.util.Calendar;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

Import Javax.annotation.Resource;

Import Org.apache.cxf.common.util.StringUtils;

Import Com.cc.hkjc.domain.HcNum;
Import Com.cc.hkjc.domain.Zstj;
Import Com.cc.hkjc.service.PhoneService;
Import Com.cc.hkjc.service.ZstjService;

public class Springqtz {
private static int count=0;
@Resource
Private Zstjservice Zstjservice;

@Resource
Private Phoneservice Phoneservice;

public void execute () {
  
}
}

4, in the Web. config spring-timer.xml

Springqtz Time Task Scheduling

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.