日期:2014-05-17 浏览次数:20920 次
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- 要调用的工作类 --> <bean id="leaveQuartz" class="util.LeaveQuartz"></bean> <!-- 定义调用对象和调用对象的方法 --> <bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 调用的类 --> <property name="targetObject"> <ref bean="leaveQuartz" /> </property> <!-- 调用类中的方法 --> <property name="targetMethod"> <value>quartzStart</value> </property> </bean> <!-- 定义触发时间 --> <bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="jobtask" /> </property> <!-- cron表达式 --> <property name="cronExpression"> <value>0 0/1 9-19 * * ?</value> </property> </bean> <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 --> <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="doTime" /> </list> </property> </bean> </beans>
@Controller public class LeaveQuartz { private EmployeeLeaveService employeeLeaveService; @Resource(name = "employeeLeaveService") public void setEmployeeLeaveService(EmployeeLeaveService employeeLeaveService) { this.employeeLeaveService = employeeLeaveService; } public void quartzStart() { updateLeaveingsNumber(); } public void updateLeaveingsNumber() { double leaveingsNumber = HRConstants.MATH_ZORE; employeeLeaveService.getEmployeeLeaveMaxId(); } }