0

我正在尝试设置 CronTriggerFactoryBeanusing Spring,它有一个名为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. 我想对了吗?

如何消除此错误?如何为此创建自定义编辑器?

4

2 回答 2

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;
}

请参阅第 23 章。调度和线程池

<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>
于 2012-07-26T13:33:26.103 回答
0

您需要创建一个转换模式。

  1. 更改 <property name="jobDetail" value="Group Trigger"></property><property name="jobDetail" ref="myconversion" />
  2. 添加转换模式:

    <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> 
    

于 2012-07-26T13:36:53.593 回答