quartz 版本升级

用spring 3+quartz 2,然后照着网上的demo做的时候,可能你会遇到

class org.springframework.scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class 

 这样的问题 ,就是说spring里的CronTriggerBean类继承的居然是quartz中的一个接口,CronTrigger在quartz 2的版本中是一个接口。而在quartz  1中它是个类。所以,一种方法是降低quartz  版本可以解决这个问题。

另一种方法是使用另一个spring提供的CronTriggerFactoryBean。具体可看这里

<?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:cache="http://www.springframework.org/schema/cache"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:jms="http://www.springframework.org/schema/jms" xmlns:lang="http://www.springframework.org/schema/lang"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:oxm="http://www.springframework.org/schema/oxm"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd    
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd    
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd    
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd    
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd    
        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.1.xsd    
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.1.xsd    
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd    
        http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd    
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd    
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd    
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">

	<!-- 任务调度 -->
	<!-- 线程执行器配置,用于任务注册 -->
	<bean id="executor"
		class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
		<property name="corePoolSize" value="10" />
		<property name="maxPoolSize" value="100" />
		<property name="queueCapacity" value="500" />
	</bean>

	<!-- 要调用的工作类 -->
	<bean id="sayHelloService" class="com.cnge06.SayHelloService"></bean> 
	
	<!-- 定义调用对象和调用对象的方法 -->
	<bean id="jobtask"
		class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<!-- 调用的类 -->
		<property name="targetObject" ref="sayHelloService"></property>
		<!-- 调用类中的方法 -->
		<property name="targetMethod" value="say"></property>
	</bean>
	<!-- 定义触发时间 -->
	<bean id="doTime" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail" ref="jobtask"></property>
		<!-- cron表达式 -->
		<property name="cronExpression" value="* * * * * ?"></property>
	</bean>
	<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
	<bean id="startQuertz" 
		class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="doTime" />
			</list>
		</property>
	<property name="taskExecutor" ref="executor" />
	</bean>
</beans>

猜你喜欢

转载自cnge06.iteye.com/blog/1859044