POM. XML file
<!--timer task quartz need to import coordinates-- <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>1.8.5</version> </dependency >
Similar to the controller code:
Package Com.xiaowu.quartz.demo;import Java.util.date;import Org.springframework.scheduling.annotation.scheduled;import org.springframework.stereotype.component;/*** * * Quartz set the project global Schedule Task * * @Component The meaning of annotations refers to the components, we can use this annotation to annotate when the component is not well categorized. General public methods I will use this note * * * @author WQ * */@Componentpublic class Quartzdemo {@Scheduled (cron = "0 0/1 * * * *?")//per minute The clock executes a public void work () throws Exception {System.out.println ("Perform dispatch task:" +new Date ()); } @Scheduled (fixedrate = 5000)//Execute public void play () throws Exception {System.out.println ("execute Q") every 5 seconds Uartz Timer Task: "+new Date ()); } @Scheduled (cron = "0/2 * * * * *?")//every 2 seconds public void dosomething () throws Exception {System.ou T.println ("Perform a scheduled task every 2 seconds:" +new Date ()); } @Scheduled (cron = "0 0 0/1 * *?")//hourly execution of public void Gowork () throws Exception {System. Out.println ("Timed tasks performed once per hour:" +new Date ()); } }
Start the Springboot project and you can.
public static void Main (string[] args) { springapplication.run (chapter1application.class, args); }
As follows:
Simple example of springboot Integrated Quartz timing Task