在Spring中配置Quartz

今天在spring中配置了一下Quartz,发现最新版本的Quartz 2.0和Spring 3.0.5不兼容,后来看了Quartz 2.0的API,发现原来Quartz 2.0把JobDetail类改成了接口,所以直接导致spirng的代码报错,换成了Quartz 1.8后就可以正常工作了,以下是具体2种配置方法

 

1)

<bean name="exampleJob" class="com.gwj.commons.quartz.ExampleJob" lazy-init="false" autowire="no" />
	<bean id="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean" lazy-init="false" autowire="no">
	    <!-- 调用的类 -->
	    <property name="targetObject">
	        <ref bean="exampleJob"/>
	    </property>
	    <!-- 调用类中的方法 -->
	    <property name="targetMethod">
	        <value>work</value>
	    </property>
	    <property name="concurrent" value="false" />
	</bean>
	
	<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean" lazy-init="false" autowire="no">
	    <property name="jobDetail">
	    	<ref bean="jobtask" />
	    </property>
	    <!-- run every morning at 6 AM -->
	    <property name="cronExpression" value="0/30 * * * * ?" />
	</bean>
	
	<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" autowire="no">
	    <property name="triggers">
	        <list>
	            <ref local="cronTrigger" />
	        </list>
	    </property>
	</bean>

 2)

<bean id="jobtask" class="org.springframework.scheduling.quartz.JobDetailBean" lazy-init="false" autowire="no">
	    <!-- 调用的类 -->
	    <property name="jobClass" value="com.gwj.commons.quartz.QuartzJob" />
	</bean>
	
	<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean" lazy-init="false" autowire="no">
	    <property name="jobDetail">
	    	<ref bean="jobtask" />
	    </property>
	    <!-- run every morning at 6 AM -->
	    <property name="cronExpression" value="0/30 * * * * ?" />
	</bean>
	
	<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" autowire="no">
	    <property name="triggers">
	        <list>
	            <ref local="cronTrigger" />
	        </list>
	    </property>
	</bean>
 

你可能感兴趣的:(spring,bean,工作,quartz)