1.spring配置文件中bean属性标签加上
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd ;
在中添加定时器任务扫描
<!-- task任务扫描注解 -->
<task:annotation-driven />
2.写定时器任务 ,类上添加spring标签@Component
@Component
public class GenerateState{
private static Log log = LogFactory.getLog(GenerateState.class.getName());
@Resource
private ProjectService projectService;
@Scheduled(cron = "00 00 00 ? * *")//定时器时间设置 根据需要设置
public void executeTask() throws Exception {
try {
//此处添加定时器任务
} catch (Exception e) {
e.printStackTrace();
}
}
}