quartz定时器配置实现:
假如有一个RedisTask类有一个myFunc方法,配置其为定时执行的方法:
<!--首先是配置要定时加载的目标类-->
<bean id="redisTaskAction" class="com.me.RedisTask"/>
<!--配置定时执行的方法参数-->
<bean id="redisTaskMethod" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="redisTaskAction" />
<property name="targetMethod" value="myFunc" />
<property name="concurrent" value="false"/>
</bean>
<!--配置触发器,每5分钟触发一次-->
<bean id="redisTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="redisTaskMethod" />
<property name="cronExpression" value="0 0/5 * * * ?" />
</bean>
<!--最后配置启动定时器-->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="redisTaskTrigger"/>
...
</list>
</property>
</bean>
依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.0</version>
</dependency>