Spring-Task定时任务的使用
Spring Task是Spring 3.0后推出的定时任务模块,职责是按周期后台自动执行任务,Spring Task利用cron表达式实现灵活的定时处理。
检查是否存在依赖包

在applicaitonContext.xml中检查schema文档并开启注解模式
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mv="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

开发task类完成定时任务的业务逻辑
使用@Scheduled注解完成定时任务的声明,参数为cron表达式

cron表达式实例


浙公网安备 33010602011771号