---
title: "SpingMvc定时器"
author: "HC-JAVA"
date: "2013-04-08T20:31:34Z"
tags: []
categories: ["编程语言"]
slug: "spingmvc"
draft: false
lastmod: "2013-04-08T20:31:34Z"
id: 1844088
url: "https://hc-java.iteye.com/blog/1844088"
---

1、配置springMvc的配置文件

&lt;beans xmlns="http://www.springframework.org/schema/beans"  

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"  

    xmlns:task="http://www.springframework.org/schema/task"  

    xsi:schemaLocation="http://www.springframework.org/schema/beans   

    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  

    http://www.springframework.org/schema/task   

    http://www.springframework.org/schema/task/spring-task-3.0.xsd"&gt;

  

  &lt;!-- 定时器开关 --&gt;

&lt;task:annotation-driven /&gt;

  

    &lt;bean id="authCodeTimer" class="com.master.web.timer.AuthCodeTimer"&gt;&lt;/bean&gt;  

  

    &lt;task:scheduled-tasks&gt;

        &lt;task:scheduled ref="authCodeTimer" method="test" cron="0 22 15 * * ?" /&gt;

    &lt;/task:scheduled-tasks&gt;

    

&lt;/beans&gt;

 

2、java代码

/\**

 * 验证码定时器

 * @author hc

 *

 \*/

public class AuthCodeTimer {

 

AuthCodeService authCodeService = new AuthCodeServiceImpl();

 

/\**

\* 计算每天的用户数据

\*/

public void test(){

System.out.println(“启动了”);

}

}