Spring整合Quartz

1.任务DemoJob.java 
package com.xiajin.timetask;

import java.util.Date;

public class DemoJob {
	
	public void execute() {
		System.out.println(new Date().toString() + " is executed.");
	}

}
2.配置文件:
<?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="someJob" class="com.xiajin.timetask.DemoJob" />

	<bean id="jobDetailBean"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject" ref="someJob" />
		<property name="targetMethod" value="execute" />
	</bean>

	<bean id="cronTriggerBean"
		class="org.springframework.scheduling.quartz.CronTriggerBean">
		<property name="jobDetail" ref="jobDetailBean" />
		<property name="cronExpression" value="40 25 11 * * ?" />
		<!-- 每天18:30自动执行指定的任务:秒(0-59) 分(0-59) 小时(0-23) 每月第几天(1-31) 月(1-12 orJAN-DEC) 每星期第几天(1-7 or SUN-SAT) 年(1970-2099) -->
	</bean>

	<bean id="schedulerFactoryBean"
		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="cronTriggerBean" />
			</list>
		</property>
	</bean>
</beans>

你可能感兴趣的:(java,spring,xml,quartz,sun)