http://www.springframework.org/schema/task  
http://www.springframework.org/schema/task/spring-task-3.2.xsd

 配置文件中加入这个

     <!-- task任务扫描注解 -->  
	<task:annotation-driven/>
	
	<context:component-scan base-package="com.*******.tog.*.time"></context:component-scan>

  一定要让Spring扫描这个包

         @Scheduled(cron="${timing.synchronous}")//每天凌晨2点执行一次  ----从properties中获取需要定时的时间
         public void taskCycle(){ logger.debug("提示:timingSwitch= " + timingSwitch); if(timingSwitch != null && timingSwitch.equals("no")){  ---------下面这个是服务器 从配置中配置需要那台服务器同步                       logger.debug("提示:不进行数据同步,如需同步,请将app-config.properties中的timing.Switch设置为yes"); return; }else if(timingSwitch != null && timingSwitch.equals("yes")){ }else{ logger.debug("提示:参数timing.Switch超出了范围,仅允许[yes/no]!"); return; }

  定时方法很简单,也很好用。

posted on 2015-08-25 15:01  Bonnat  阅读(618)  评论(0编辑  收藏  举报