设置org.springframework.scheduling.quartz.JobDetailBean的bean属性'jobClass'

时间:2011-05-24 09:55:31

标签: java spring java-ee dependency-injection quartz-scheduler

我的项目有一个Quartz调度程序,我将JobDetailBean设置为

<bean id="deadlineFailureChecker" class="info.release.scheduler.DeadlineFailureChecker" />

<bean id="workingHourPerDayUpdater" class="info.release.scheduler.WorkingHourPerDayUpdater" />

<bean name="scheduledJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass" value="info.release.scheduler.ScheduledJob" />
    <property name="jobDataAsMap">
        <map>
            <entry key="deadlineFailureChecker" value-ref="deadlineFailureChecker" />
            <entry key="workingHourPerDayUpdater" value-ref="workingHourPerDayUpdater" />
        </map>
    </property>     
</bean>

现在我想将一个属性值传递给我做的info.release.scheduler.ScheduledJob:

<bean id="scheduledJobBean" class="info.release.scheduler.ScheduledJob">
    <property name="afrodite" ref="afrodite" />
</bean>

<bean name="scheduledJob" class="org.springframework.scheduling.quartz.JobDetailBean">
    <property name="jobClass">
        <bean factory-bean="scheduledJobBean" factory-method="getClass"></bean>
    </property>
    <property name="jobDataAsMap">
        <map>
            <entry key="deadlineFailureChecker" value-ref="deadlineFailureChecker" />
            <entry key="workingHourPerDayUpdater" value-ref="workingHourPerDayUpdater" />
        </map>
    </property>     
</bean>

但以下System.out.println正在打印null

@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    System.out.println("============================================="+this.afrodite);

}

此方法属于info.release.scheduler.ScheduledJob extends QuartzJobBean

我也做了一个实验,我设置了

<bean id="scheduledJobBean" class="info.release.scheduler.ScheduledJob">
    <property name="afrodite" ref="afrodite" />
</bean> 

<bean id="scheduledJobBean" class="info.release.scheduler.ScheduledJob" init-method="init">
    <property name="afrodite" ref="afrodite" />
</bean>

public void init() {
    System.out.println("============================================="+this.afrodite);
}

在此init中,System.out.println不打印null而是打印值。

我无法理解发生了什么! JobDetailBean是否重新实例化jobClass对象?

我需要设置jobClass JobDetailBean属性的值类的属性。

谢谢和问候。

1 个答案:

答案 0 :(得分:2)

我也是同一个问题。我最终将其设为私有静态。如下所示

private static afrodite;