设置bean属性“jobClass” org.springframework.scheduling.quartz.JobDetailBean 的
我的项目有一个 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 对象?
我需要的是设置 JobDetailBean
的 jobClass
属性的值类属性。
谢谢和问候。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题。我最终将其设为私有静态。使它像下面这样
I 'd same issue. I ended up with making it private static. make it like as follows