來源:http://itssh.cn/post/937.html
spring task定時(shí)調(diào)度碍讯,配置簡單窟绷,無法集群住闯,需單獨(dú)部署
xml配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.1.xsd">
<!-- 定時(shí)器開關(guān) -->
<task:annotation-driven />
<!-- 定義定時(shí)任務(wù) -->
<bean id="myTaskXml" class="cn.sunmeng.demo.demo1.service.MyTaskXml" />
<!-- 任務(wù)觸發(fā)時(shí)間配置 -->
<task:scheduled-tasks>
<task:scheduled ref="myTaskXml" method="executeTask" cron="*/5 * * * * ?"/>
</task:scheduled-tasks>
</beans>
java代碼:
package cn.sunmeng.demo.demo1.service;
/**
* @ClassName: MyTaskXml.java
* @Description: TODO
* @author: SM(sm0210@qq.com)
* @date: 2016年12月5日 下午6:59:19
*/
public class MyTaskXml {
/**
* 定時(shí)任務(wù)
*/
public void executeTask(){
System.out.println("spring 定時(shí)任務(wù)執(zhí)行 executeTask() 方法铺敌。。椅棺。");
}
}