1.applicationContext.xml 添加约束
xmlns:task="http://www.springframework.org/schema/task" http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd"> <!--放开定时任务配置 --> <task:annotation-driven />
2. 新建包 com.rb.job
3. 包内添加TaskJob.class
package com.rb.job; import java.util.Date; import org.apache.tools.ant.util.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import com.rb.service.UserService; //定时任务类 @Component public class TaskJob { @Autowired UserService userService; @