Spring talk简单配置

XMl文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.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-3.0.xsd">

<task:annotation-driven /> <!-- 定时器开关-->
<bean id="TalkController" class="cn.springmvc.talk.TalkController"></bean>
<task:scheduled-tasks>
<!--
这里表示的是每隔五秒执行一次
-->
<task:scheduled ref="TalkController" method="talkTest" cron="*/5 * * * * ?" />
</task:scheduled-tasks>

<!-- 自动扫描的包名 -->
<context:component-scan base-package="cn.springmvc.talk" />
</beans>

java文件

package cn.springmvc.talk;

public class TalkController {
public void talkTest(){
System.out.println("任务开始");
}

}

原文地址:https://www.cnblogs.com/Seeasunnyday/p/5483071.html