xmlns Add the following content
xmlns:task= "Http://www.springframework.org/schema/task"
Then xsi:schemalocation add the following content
http://www.springframework.org/schema/task http://
And finally, our task mission scan annotations.
<task:annotation-driven/>
My configuration scan location is:
<context:annotation-config/> <bean class= " Org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor "/> <context: Component-scan base-package= "Com.test"/>
@Component //import org.springframework.stereotype.Component; Public class Mytestserviceimpl implements Imytestservice { @Scheduled (cron= "0/5 * * * * * ?) ") // every 5 seconds @Overridevoid myTest () { System.out.println ("Enter Test"); } }
1, spring @scheduled annotations need to write on the implementation,
2, the task method of the timer can not have a return value (if there is a return value, spring initialization will tell you that there is an error, you need to set a Proxytargetclass value of true, go to Baidu Google bar)
3, the implementation of the class to have component annotations @component
The rest is corn expression, specific use and parameters please Baidu Google,
Here are just a few examples.
Cron expression meaning
"0 0 12 * *?" Triggered 12 o'clock noon every day
"0 15 10?" * * "trigger 10:15 every day"
"0 15 10 * *?" Triggered 10:15 daily
"0 15 10 * *?" * "10:15 per day" trigger
"0 15 10 * *?" 2005 "2005-year daily 10:15 Trigger
"0 * 14 * *?" Daily from 2 o'clock in the afternoon to 2:59 per minute trigger
"0 0/5 14 * *?" Every 5 minutes from 2 o'clock in the afternoon to 2:55
"0 0/5 14,18 * *?" Daily from 2 o'clock in the afternoon to 2:55 and from 6 to 6:55 every 5 minutes for two time periods
"0 0-5 14 * *?" Daily 14:00 to 14:05 triggers per minute
"0 10,44 14?" 3 WED "March of 14:10 and 14:44 triggers per Wednesday
"0 15 10?" * MON-FRI "10:15 triggers per Monday, Tuesday, Wednesday, Thursday, Friday
Perform timed tasks using spring @Scheduled annotations