http://www.javaranch.com/journal/200711/combining_spring_and_quartz.html我按照上述网页的内容编写了quartz应用,但是去总是不能运行(一点反应都没有,没法调试),我也不知道原因,不知道谁能不能指点一下:
配置文件:
<bean name="welcomeBean" class="mblog.service.daemon.RanchBean">
<property name="message" value="Welcome at JavaRanch" />
</bean>
<bean id="methodInvokingJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="welcomeBean" />
<property name="targetMethod" value="welcome" />
</bean><bean id="ranchTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="methodInvokingJob" />
<property name="startDelay" value="0" />
<property name="repeatInterval" value="1000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="ranchTrigger" />
</list>
</property>
</bean>
// java代码:
package mblog.service.daemon;
public class RanchBean {
private String message; public void setMessage(String message) {
this.message = message;
} public void welcome() {
System.out.println("[JOBBEAN] " + message);
}
}这算是quartz界的hello world了,但是却不能运行,谁能指点一下迷津或者告诉我一些排查错误的思路也行!
谢谢了
配置文件:
<bean name="welcomeBean" class="mblog.service.daemon.RanchBean">
<property name="message" value="Welcome at JavaRanch" />
</bean>
<bean id="methodInvokingJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="welcomeBean" />
<property name="targetMethod" value="welcome" />
</bean><bean id="ranchTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="methodInvokingJob" />
<property name="startDelay" value="0" />
<property name="repeatInterval" value="1000" />
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="ranchTrigger" />
</list>
</property>
</bean>
// java代码:
package mblog.service.daemon;
public class RanchBean {
private String message; public void setMessage(String message) {
this.message = message;
} public void welcome() {
System.out.println("[JOBBEAN] " + message);
}
}这算是quartz界的hello world了,但是却不能运行,谁能指点一下迷津或者告诉我一些排查错误的思路也行!
谢谢了
成功了再写一个hellowworld整合到spring里面
这2步都成功了
再把quartz整合到spring里面
第一步能够执行,第二步不明白你是什么意思?第三步是没有效果的,我不知道会不会是lib包版本有问题
我上网下的完整的1.6.6版的jar包,会有什么问题呢?最多是跟其他jar包存在兼容性问题,但是检查兼容性就超过我的能力范围之外了
通过大量的搜索发现,我在beans配置中声明了 default-lazy-init="true" 所以导致 SchedulerFactoryBean 没有立即加载,所以定时器也就没有执行。现在:
<bean lazy-init="false" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
...后,终于有反应了:
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'methodInvokingJob': FactoryBean which is currently in creation returned null from getObject预知后事如何,请听楼下分解
若在spring配置文件中配置了quartz相关参数,则不能够设置default-autowire="byName"属性,否则后台会报Table 'database.qrtz_locks' doesn't exist异常,这是因为若使用了autowire,spring集成quartz,会默认使用数据库存储job状态(而不是存储在内存中),spring会自动将dataSource(hibernate配置的数据库)配置为quartz存储数据库,而我们的数据库中又没有quartz所需的数据表,因此就会报出如上异常;若工程有多个spring配置文件,则只需当前配置quartz的文件不设置default-autowire="byName"即可。