此文章是基于 搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台
一. jar包介绍
1. spring-framework-4.3.4.RELEASE 的 libs 文件夹下得到:
spring-context-support-4.3.4.RELEASE.jar
2. quartz-2.2.3.jar
二. 相关文件介绍
1. applicationInfrastructure.xml,定时器配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <!-- 定时器bean类定义 --> <bean id="flexTimeJob" class="com.ims.infrastructure.quartz.FlexTimeJob"> <!-- 指定定时器调度工厂 --> <property name="scheduler" ref="flexTimeSchedulerFactory" /> <!-- 向定时器注入bean --> </bean> <!-- 任务定义 --> <bean id="flexTimeJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!-- 任务所在的类 --> <property name="targetObject" ref="flexTimeJob" /> <!-- 任务所对应的方法名 --> <property name="targetMethod" value="executeInternal" /> <property name="concurrent" value="false" /> </bean> <!-- 任务触发器 --> <bean id="flexTimeJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail" ref="flexTimeJobDetail"/> <property name="cronExpression" value="0 0 0 ? * *"/> <!-- 默认每天凌晨0点整打印 --> <property name="startDelay" value="10000"/> <!-- 延迟10秒(10000毫秒)启动 --> </bean> <!-- 调度工厂,触发器集合 --> <bean id="flexTimeSchedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="triggers"> <list> <ref bean="flexTimeJobTrigger"/> </list> </property> </bean> </beans>