我正在尝试使用Spring
设置CronTriggerFactoryBean,并且它有一个名为 JobDetail 的属性,我试图初始化。
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="name" value="NTrigger"></property>
<property name="group" value="Group Trigger"></property>
<property name="jobDetail" value="Group Trigger"></property>
<property name="cronExpression" value="${quartz.slaPollerCronExpression.timeInterval}"></property>
</bean>
但我收到的错误是:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'cronTriggerForSLAPoller' defined in ServletContext resource [/WEB-INF/config/quartz
-config.xml]: Initialization of bean failed; nested exception is
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value
of type 'java.lang.String' to required type 'org.quartz.JobDetail' for property
'jobDetail'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type [java.lang.String] to required type [org.quartz.JobDetail
for property 'jobDetail': no matching editors or conversion strategy found.
我认为它需要String
作为默认类型。
我看一下[propertyeditors][1]
。我想我需要使用ClassEditor
。我的想法是否正确?
如何删除此错误?如何为此创建自定义编辑器?
答案 0 :(得分:1)
您似乎需要传递引用而不是字符串:
Failed to convert property value of type 'java.lang.String' to required type 'org.quartz.JobDetail' for property 'jobDetail'
<强> CronTriggerFactoryBean 强>
/**
* Set the JobDetail that this trigger should be associated with.
*/
public void setJobDetail(JobDetail jobDetail) {
this.jobDetail = jobDetail;
}
请参阅 Chapter 23. Scheduling and Thread Pooling 。
<bean id="exampleJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="exampleBusinessObject" />
<property name="targetMethod" value="doIt" />
<property name="concurrent" value="false" />
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="exampleJob" />
<!-- Runs every morning at 6 AM -->
<property name="cronExpression" value="0 0 6 * * ?" />
</bean>
答案 1 :(得分:0)
您需要创建转换模式。
<property name="jobDetail" value="Group Trigger"></property>
更改为<property name="jobDetail" ref="myconversion" />
添加转换模式:
<bean id="myconversion" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.nuance.ndm.ou.jobs.MserverCalllogTransformerJob" />
<property name="jobDataAsMap">
<map>
<entry key="groupTrigger" value="Group Trigger"" />
</map>
</property>