<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- 1 引入spring定时器的支持类 同时指定作用于那个类 哪个方法 --> <bean id="helloWord" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!--targetObject指的是触发对象所在的类 这个类已经在spring中注册了,这里直接把bean的id拿过来用就可以了--> <property name="targetObject" ref="productServiceImpl" /> <!-- targetMethod指的是触发的方法,当触发条件符合时,就会自动执行test方法 --> <property name="targetMethod" value="sendEmail" /> </bean> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail"> <ref bean="helloWord" /> </property> <property name="cronExpression"> <value>0 0/2 20 * * ?</value> </property> </bean> <!--公共启动任务 3--> <bean id="quartzFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <!-- triggers属性接受一组触发器 --> <property name="triggers"> <list> <ref local="cronTrigger" /> </list> </property> </bean> </beans>
原文:http://blog.csdn.net/sxj_world/article/details/20715865