1 在springmvc配置文件中新增以下配置
<!-- 此处对于定时时间的配置会被注解中的时间配置覆盖,因此,以注解配置为准 --> <task:scheduled-tasks scheduler="myScheduler"> <task:scheduled ref="scheduledHealthFlowerManager" method="resetWater" cron="0 */1 * * * ?"/> </task:scheduled-tasks> <task:scheduler id="myScheduler" pool-size="10" />
2 java类
@Component("scheduledHealthFlowerManager") public class HealthFlowerTaskUtil { @Autowired HealthFlowerDao healthFlowerDao; public void resetWater(){ try { healthFlowerDao.resetWater(); } catch (Exception e) { e.printStackTrace(); } System.out.println("成功重置浇水次数"); } }
引用自:http://sanniangmiao.iteye.com/blog/2148168