spring定时任务

参考:http://gong1208.iteye.com/blog/1773177


spring配置文件:

<!-- spring定时任务 定时统计设备定检率-->
	<bean id="springTimer" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject">
			<bean class="com.gf.equipment.controller.EquipmentStatisticsHistoryController" />
		</property>
		<property name="targetMethod" value="fixedInspectionRate" />
		<property name="concurrent" value="false" /><!-- 作业不并发调度 -->
	</bean>
	<!-- 配置作业调度的触发方式(触发器) -->
	<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail" ref="springTimer" />
		<property name="cronExpression" value="0 39-45 14 * * ?" /><!--每天14:39至14:45每分钟一次触发 -->
	</bean>
	<!-- 配置调度工厂 -->
	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="cronTrigger" />
			</list>
		</property>
	</bean>

相关java类
package com.gf.equipment.controller;

import com.gf.common.BaseController;
import com.gf.equipment.service.EquipmentService;
import com.gf.equipment.service.EquipmentStatisticsService;
import com.gf.pf.model.Flexigrid;
import com.gf.pf.service.LogService;
import com.gf.pf.service.MyBatisService;
import com.gf.util.DateUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * Description: 设备统计(Spring定时任务,定时统计设备定检率,存入数据库,以供查询)
 * Package Name: com.gf.equipment.controller
 * User: 
 * Date: 2017-06-05
 * Time: 15:11
 */
@Controller
@RequestMapping("/equipmentStatisticsHistory")
public class EquipmentStatisticsHistoryController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(EquipmentStatisticsHistoryController.class);

	@Autowired
	private MyBatisService myBatisService;
	@Autowired
	private EquipmentService equipmentService;
	@Autowired
	private LogService logService;
	@Autowired
	private EquipmentStatisticsService equipmentStatisticsService;


	/**
	 * 定时统计定检率存入数据库
	 *
	 * @return
	 */
	public void fixedInspectionRate() {
		logger.info("定时统计定检率存入数据库");
		System.out.println(DateUtil.date_string(new Date()));
	}

}

启动项目测试一下,看控制台输出



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值