A .pom.xml
<dependency> <groupId> JUnit </ groupId> <artifactId> JUnit </ artifactId> <version> 4.11 </ version> <scope> test </ scope> </ dependency> <dependency> <groupId> org.springframework </ groupId> <artifactId> ressort contexte </ artifactId> <version> 4.3.20.RELEASE </ version> </ dependency> <dependency> <groupId> org.springframework </ groupId> <artifactId> ressort web </ artifactId > <version> 4.3.20.RELEASE </ version> </ dependency>
classe Mandat
public class {TaskService publique firstTask vide () { SimpleDateFormat SimpleDateFormat = new SimpleDateFormat ( "aaaa-mm-jj-HH-MM: SS: MS"); Format String = simpleDateFormat.format (new Date ()); System.out.println ( "数据库备份时间1:" Format +); } SecondTask public void () { SimpleDateFormat SimpleDateFormat = new SimpleDateFormat ( "aaaa-MM-JJ-HH-mm: ss: ms"); Format String = simpleDateFormat.format (new Date ()); System.out.println ( "数据库备份时间2:" Format +); } }
三 .applicationContext.xml
<xml version = "1.0" encoding = "UTF-8"?> <haricots xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org / 2001 / XMLSchema instance " xmlns: task = "http://www.springframework.org/schema/task" xsi: schemaLocation =" http://www.springframework.org/schema/beans http: // www. springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd "> <bean id = "taskService" class = "com.wj.TaskService"> </ bean> <-配置定时规则->! <tâche: les tâches planifiées-> <- retard initial :! combien de millisecondes après le démarrage du serveur pour effectuer des tâches régulières commencent -> <- exécuté une fois le nombre de millisecondes tâches régulières retard fixe :! -> <- Cron:可以指定复杂定时任务,前文Quartz有介绍,不再叙述-> <tâche: prévue ref = méthode "taskService" = "firstTask" initial retard = "10000" retard fixe = "2000 "/> <tâche: prévue ref =" « method = "taskService secondTask" initial retard = "20000" retard fixe = "4000"/> </ tâche: programmées-tâches> </ beans>
Quatre résultats d'exploitation: