以下是本人另外一种实现方式,跟@Scheduled注解配置有点不一样
1.在xml里加入task的命名空间
xmlns:task="http://www.springframework.org/schema/task"
2.在
xsi:schemaLocation加http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.3.xsd
3.定时器设置
<bean name="testTask" class="sy.scheduler.MediaTask" lazy-init="false"></bean>
<task:scheduled-tasks>
<task:scheduled ref="testTask" method="TaskJob" cron="0/2 * * * * ?"/>
</task:scheduled-tasks>
4.后台定时器代码
package sy.scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import sy.service.AppBusinessServiceI;
public class MediaTask {
public void TaskJob() {
System.out.println("this is timer job...");
}
}