<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"
default-lazy-init="false">
<context:annotation-config />
<context:component-scan base-package="com.tc.mytask" />
<!-- 开启这个配置,spring才能识别@Scheduled注解 -->
<task:annotation-driven />
</beans>
package com.tc.mytask;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class TaskJob {
@Scheduled(cron="0/5 * * * * ? ")
public void job(){
System.out.println("任务进行中。。。。");
}
}
看配置是没有问题的;
或者你测试一下官方的这种方式:http://spring.io/guides/gs/scheduling-tasks/
定义一个任务是很简单的实现TimerTask的run方法就可以了.
如下:SayHelloTask.java
1package test.timerTask;
2
3import java.util.TimerTask;
4
5public class ......
答案就在这里:spring执行定时任务
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
抱歉,新建的项目忘记在web.xml里配置spring
抱歉,新建的项目忘记在web.xml里配置spring