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> </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