星空网 > 软件开发 > Java

Spring 定时任务配置

1.applicationContext.


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

配置中加入

<task:annotation-driven/>

这个是用来启用自动的注解解析。

 

2.编写POJO

@Component public class DailyPiracyJob {	  Logger logger = LoggerFactory.getLogger(this.getClass());    @Autowired  	private AppInfoService appInfoService;	@Scheduled(cron = "0 0 23 * * ?")	public void scan() throws Exception {		try {			List<AppInfo> allAppList = appInfoService.selectAllAppInfo();			if(null != allAppList && allAppList.size() > 0){				for(AppInfo appInfo : allAppList){					appInfoService.insertDailyPiracy(appInfo.getAppMd5());				}			}		} catch (Exception e) {			logger.error("error when Channel Monitoring.", e);		}	}}

  @Compont 注解,是让Spring context 可以扫描到,并自动注入需要的bean

      @Scheudle 核心注解,不能有返回值,cron是定义了任务运行的间隔,具体,请参考网上其他教程

需要注意的是,在applicationContext.


原标题:Spring 定时任务配置

关键词:Spring

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

汇丰银行预约指南:全面了解预约流程及注意事项 :https://www.xlkjsw.com/news/60969.html
香港公司怎么变更强积金扣款账户 :https://www.kjdsnews.com/a/1837386.html
香港公司怎么变更强积金扣款账户 :https://www.xlkjsw.com/news/60970.html
深度解析:海牙体系保护期为几年 :https://www.kjdsnews.com/a/1837387.html
深度解析:海牙体系保护期为几年 :https://www.xlkjsw.com/news/60971.html
探秘美国加州企业——股东信息查询全攻略 :https://www.kjdsnews.com/a/1837388.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流