spring,springmvc 定时任务

来源:互联网 发布:国家经济数据泄密 编辑:程序博客网 时间:2024/06/06 07:29

注解模式



加上该标头
<beans  xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation=" http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">



配置文件
   
<!-- 配置注解定时扫描任务   -->       <task:annotation-driven/>     <!-- 扫描路径  -->       <context:component-scan base-package="扫描包的地址">   </context:component-scan> 


    
CLASS代码
// 表示扫描该定时任务@Componentpublic class Class{ // 时间间隔,10秒运行一次@Scheduled(cron = "0/10 * * * * ? ")public void taskCycle() {//code}}






非注解模式



加上该标头
<beans  xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation=" http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">



配置文件
<!-- ref参数指定的即任务类,method指定的即需要运行的方法,cron表示多长时间运行一次(60秒运行一次) --><task:scheduled-tasks><task:scheduled ref="任务类" method="运行的方法" cron="0/60 * * * * ?"/></task:scheduled-tasks>  <context:component-scan base-package="扫描的包" />  




CLASS
@Service("注入service,必须注入")public class SalseandloadLogController { public void IntegralRuleFlexible() { //code}}


0 0