spring task 定时任务 配置

来源:互联网 发布:日本和服淘宝 编辑:程序博客网 时间:2024/05/21 07:19

在spring配置文件中 添加

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


http://www.springframework.org/schema/task  
http://www.springframework.org/schema/task/spring-task-3.2.xsd



<context:component-scan base-package="com.yafco.yjzx.controller" />  设定范围


<task:annotation-driven />
<!--  打开springMVC定时器开关 -->
<!-- 设置需要定时启动的方法 -->
<bean id="ceshi" class="com.yafco.yjzx.controller.cs.Ceshi" scope="singleton"/>
<task:scheduled-tasks>  
        <task:scheduled ref="ceshi" method="taskCycle" cron="0/5 * * * * ?" />  <!-- 每隔五秒执行一次  --> 
    </task:scheduled-tasks>  


通过spring控制,java文件不用改动。




原创粉丝点击