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

发布于 2024-11-09 12:51:10 字数 2676 浏览 0 评论 0原文

我的项目有一个 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>

Now,因为我想将属性值传递给我所做的 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扩展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 对象?

我需要的是设置 JobDetailBeanjobClass 属性的值类属性。

谢谢和问候。

My project has a Quartz scheduler and I am setting the JobDetailBean as

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

Now as I want pass a property value to the info.release.scheduler.ScheduledJob I did:

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

But the following System.out.println is printing null:

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

}

This method belongs to info.release.scheduler.ScheduledJob extends QuartzJobBean.

I also did an experiment, I set

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

To

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

and

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

In this init the System.out.println isn't printing null rather a value.

I cannot understand what is going on! Is JobDetailBean re-instantiating the jobClass object?

What I need is to set a property of the value-class of the jobClass property of JobDetailBean.

Thanks and regards.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔戏命师 2024-11-16 12:51:11

我也有同样的问题。我最终将其设为私有静态。使它像下面这样

private static afrodite;

I 'd same issue. I ended up with making it private static. make it like as follows

private static afrodite;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文