`

Spring中Quartz的配置(spring定时任务的配置)

阅读更多
下面是触发器配置文件,把该文件引用到application.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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
	<!-- 定时器配置 -->
<!-- 配置定时器类 -->
  <bean id="triggerUtil" class="com.pro.base.util.TriggerUtil" >
  </bean>
  <!-- 指定任务(方法) -->
  <bean id="expDataBaseJob"
  	class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
  	<property name="targetObject">
  		<ref local="triggerUtil" />
  	</property>
  	<property name="targetMethod">
  		<value>expDataBase</value>
  	</property>
  </bean>
  <!-- 设定计划执行时间 -->
  <bean id="expDataBaseTrigger"
  	class="org.springframework.scheduling.quartz.CronTriggerBean">
  	<property name="jobDetail">
  		<ref local="expDataBaseJob" />
  	</property>
  	<property name="cronExpression">
  		<value>00 33 21 * * ?</value>
  	</property>
  	</bean>
  	<!-- 任务执行器配置 -->
  	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref local="expDataBaseTrigger" />
			</list>
		</property>
	</bean>
</beans>

Java类:
public class TriggerUtil {

	@Resource(name = "basicService")
	private BasicService service;  //数据库操作服务

	private TriggerUtil(){
		
	}
	
	public void expDataBase(){
		System.out.println("trigger actived........");
		System.out.println("=========================="+service+"");
		String command="exp ";
	}
	
	public BasicService getService() {
		return service;
	}

	public void setService(BasicService service) {
		this.service = service;
	}
} 


需要包quartz-1.5.1.jar

可参考:http://www.cnblogs.com/kay/archive/2007/11/02/947372.html

spring另外一种定时器配置,可参考
       http://zhidao.baidu.com/question/206891812.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics