SpringMVC之Web定时器(二)

来源:互联网 发布:数据库概念模型 图片 编辑:程序博客网 时间:2024/06/06 15:35

1.springmvc-servlet.xml的配置文件头部加上:xmlns:task="http://www.springframework.org/schema/task"

2.xsi:schemaLocation处加上:http://www.springframework.org/schema/task
                                                 http://www.springframework.org/schema/task/spring-task.xsd

3.如图所示:


4.下面是配置定时器的设置:

                    
其中:ref="taskpingController" 是你定时器的名称【首字母必须为小写】
           method="pingJob" 是你定时器的方法
           cron="0/60 * * * * ?" 是你设置的时间

5.测试用例:




记得要加上@Component注解,SpringMVC定时器还有其它的定义方法,这只是其中的一种。