在applicationContext中引入定时器的约束
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd
并且开启定时器的注解
<task:annotation-driven />
Spring 4.x 中需在类名前加@EnableScheduling
@Scheduled中可使用cron表达式和fixedDelay
在需要定时的地方打上注解 @Scheduled(cron=“0 0 1 * * ?*”) cron有生成器,里面可以定义时间