疑问:Spring配置Quartz例子出错,请看下.谢谢
研究了一天,在官方论坛也查询了很多,就是锁定不了原因。请各位朋友帮忙看看 spring的配置如下:
<bean id="emailJobBean" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="EmailJobBean"/>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="emailJobBean" />
<property name="startDelay" value="2000" />
<property name="repeatInterval" value="60000" />
</bean>
<bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger"/>
</list>
</property>
</bean>
其中被调度的bean
public class EmailJobBean extends QuartzJobBean {
protected void executeInternal(JobExecutionContext arg0)
throws JobExecutionException {
System.out.println("Quartz !!!");
}
}
启动后就保错
14:29:38,11882 ERROR Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzScheduler' defined in ServletContext resource : Invocation of init method failed; nested exception is org.quartz.SchedulerConfigException: Failure occured during job recovery. 不知道有没有朋友遇到过类似问题?请大家指点 环境我用的是resin2.1.16,jdk1.4.2,spring2.0.1,quartz1.6.0
autowire真是一个万恶的家伙, 这个问题整了我一个下午,怒了. :twisted: 设置org.quartz.jobStore.class为org.quartz.simpl.RAMJobStore也是没有用的. 因为
SchedulerFactoryBean的setDataSource(DataSource)方法javadoc说: Set the default DataSource to be used by the Scheduler. If set, this will override corresponding settings in Quartz properties.
Note: If this is set, the Quartz settings should not define a job store "dataSource" to avoid meaningless double configuration.
A Spring-specific subclass of Quartz' JobStoreCMT will be used. It is therefore strongly recommended to perform all operations on the Scheduler within Spring-managed (or plain JTA) transactions. Else, database locking will not properly work and might even break (e.g. if trying to obtain a lock on Oracle without a transaction).
Supports both transactional and non-transactional DataSource access. With a non-XA DataSource and local Spring transactions, a single DataSource argument is sufficient. In case of an XA DataSource and global JTA transactions, SchedulerFactoryBean's "nonTransactionalDataSource" property should be set, passing in a non-XA DataSource that will not participate in global transactions.
See Also: setNonTransactionalDataSource setQuartzProperties setTransactionManager LocalDataSourceJobStore
或者可以直接在spring配置中做:
按照错误信息显示,你使用的quartz应该是使用数据进行job的状态的维护的,但是在数据库中没有找到相应的table,从而无法正常建立scheduler 。
如果你的不需要错误重启功能,改成用内存维护就好。
另外可能是自动装配惹得祸,存在dataSource这个bean就自动用数据库的状态维持了。
因为这个时候你的quartz是jobstore用的HDBCJobStore模式,此时会从数据库查询任务。
你如果只是测试的话,可以在你的classpath下加一个文件quartz.properties,并且加上一句org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore 。就会采取内存存储的模式了。
看了你的问题周日自己试着作了一次....
从没出过这种错..... 看来好像是你又以什么方式去调用数据库之后产生的问题 PS:你的EmailJobBean生明方式不对应该以小写开头,并用Bean标签声明...
init method failed?是否是你的Quartz实现的接口不对? jobDataAsMap这个接口没看到配? 有没有关系?
现在就是我的hibernate和quartz的配置不能并存 , 这2者之间不会有啥不兼容吧。。。
赫赫 ,这个地方就是那个jobClass的值 就是一个类的完整名称, 我这个类没有包名,所以直接就是这么写的。
很奇怪
你没定义 id=EmailJobBean 为什么这句不报错呢
... 我只给出了和quartz相关的,其他的就还有一个hibernate的配置 然后就没有了。 去掉quartz的都很正常的跑。这个quartz跑得和hibernate一点关系都没有
总共分了3个配置 spring.xml
spring-hibernate.xml就是配置了数据源和dao,service spring-quartz.xml就是一楼的那些内容
那就是配置文件有问题
你给出来的不全吧
测试后,错误依旧。 @-@.
PS:感谢回帖。
public class EmailJobBean implements StatefulJob
你试试