spring定时任务配置

来源:互联网 发布:网络电视直播软件 编辑:程序博客网 时间:2024/06/03 12:33
ApplicationContext.xml中 加入启动定时任务需要的
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.0.xsd"

// * 处填写自定义的task包名, spring将自动扫描此包下标有定时任务注解的类方法

@Component        //类注解
//@Lazy(value=false)    //懒加载,不知道什么用,百度来的方法,自带的,注释了也好使.
public class Task {

@Autowired
private TaskService taskService;
@Scheduled(cron=" * 0 10 0 ? * MON ")    // 每周一0点10分执行  依次: 秒 分 时 日 月 星期年(前六项必有,年:无要求可省略此项)
// @Scheduled(cron=" 0/2 * * * * *")
@Async
public void signInTask(){
taskService.delSignInTask();
}
}