我是Quartz的新手,我刚刚开始使用已经使用quartz调度程序的项目。项目正在编译,但在运行时会抛出以下异常:
BeanCreationException: Error creating bean with name 'galleryBulkTrigger' defined in ServletContext resource [/WEB-INF/spring/applicationContext-scheduler.xml]: Cannot resolve reference to bean 'galleryBulkJob' while setting bean property 'jobDetail'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'galleryBulkJob' defined in ServletContext resource [/WEB-INF/spring/applicationContext-scheduler.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required
type 'java.lang.Class' for property 'jobClass'; nested exception is java.lang.IllegalArgumentException: Cannot find class [com.sgss.nove.quartz.gallery.GalleryBulkJob]:
applicationcontext定义bean如下:
<bean id="galleryBulkTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="galleryBulkJob"/>
<property name="cronExpression" value="#{noveExternalProperties['cronExpression.galleryBulk']}"/>
</bean>
<bean id="galleryBulkJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.sgss.nove.quartz.gallery.GalleryBulkJob"/>
<property name="jobDataAsMap">
<map>
<entry key="galleryBulkTask" value-ref="galleryBulkTask"/>
</map>
</property>
</bean>
,班级GalleryBulkJob
如下:
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
public class GalleryBulkJob extends QuartzJobBean {
private GalleryBulkTask galleryBulkTask;
public void setGalleryBulkTask(GalleryBulkTask galleryBulkTask) {
this.galleryBulkTask = galleryBulkTask;
}
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
galleryBulkTask.executeTask();
}
}
只要我知道它应该有用,唯一的疑问就是行:<property name="jobClass" value="com.sgss.nove.quartz.gallery.GalleryBulkJob"/>
,其中值被视为一个字符串,但是期望一个Class。
如何解决此问题?
提前致谢。
答案 0 :(得分:1)
将字符串传递给Spring上下文中的类参数是可以的。
看一下错误信息:找不到类[com.sgss.nove.quartz.gallery.GalleryBulkJob]。
由于某种原因,类似乎不存在于类路径中。