spring 定时器配置
1.spring配置文件中引入域名空间,添加标签
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
<task:annotation-driven/>
2. 组件实现实例,最好写上@Lazy(false)
@Component
@Lazy(false)
public class AutoReConnectionTask {
private static final Logger LOG = Logger.getLogger(AutoReConnectionTask.class);
@Autowired
ReConnectService reConnectService ;
@Scheduled(cron="0 0 1 * * ?") //秒 分 时 日 月 星期 年
public void taskUserOrgBrankingList(){
try {
LOG.info("定时任务 AutoReConnectionTask 刷新!");
int ret = reConnectService.reConnection();
if(ret == 1 ){
LOG.info("AutoReConnectionTask 刷新成功");
}else{
LOG.info("AutoReConnectionTask 刷新异常");
}
} catch (Exception e) {
LOG.error("定时器执行失败,orgRandkingList 到 user_orgRandkingList表 ", e);
}
}
}
3.组件扫描
<context:component-scan base-package="com.chengshu.Controller"/>