如何在XML配置中添加石英JobListener (spring-framework)



我有我的石英调度程序,触发器&在XML中配置的作业类似于-https://docs.spring.io/spring-framework/docs/1.2.x/reference/scheduling.html。

我想向这个调度器添加一个jobListener,它将在job1完成时触发另一个作业(在侦听器的jobwasperformed方法中),但我无法找到任何基于XML的jobListener用法。

这是我到目前为止所尝试的,但是bean在添加侦听器后没有初始化-

Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'listeners' of bean class [org.springframework.scheduling.quartz.SchedulerFactoryBean]: Bean property 'listeners' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

<bean id="myScheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="myTrigger" />
</list>
</property>
<property name="listeners">
<list>
<ref bean="completionListener" />
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
</props>
</property>
</bean>
<bean name="myTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="myJobDetail" />
<property name="cronExpression" value="0 3 0/1 * * ?" />
</bean>
<bean id="myJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="ABC" />
<property name="targetMethod" value="refresh" />
<property name="concurrent" value="false" />
</bean>
<bean id="completionListener" class="com.dummy.MyListener"/>

这是MyListener类-

public class MyListener implements JobListener {
@Override
public String getName() {
return "myListener";
}
@Override
public void jobToBeExecuted(JobExecutionContext jobExecutionContext) {
}
@Override
public void jobExecutionVetoed(JobExecutionContext jobExecutionContext) {
}
@Override
public void jobWasExecuted(JobExecutionContext jobExecutionContext, JobExecutionException e) {
log.info("First Job was executed");
Scheduler scheduler = jobExecutionContext.getScheduler();
try {
// Create the chained JobDetail
JobKey jobKey = new JobKey("dummyJobName", "group1");
JobDetail jobDetail = JobBuilder.newJob(DummyJob.class)
.withIdentity(jobKey).build();
// Create a one-time trigger that fires immediately
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("triggerNextJob", "group1")
.startNow()
.build();
// Schedule the next job to fire immediately
scheduler.scheduleJob(jobDetail, trigger);
log.info(DummyJob.class.getName() +
" has been scheduled executed");
} catch (Exception ex) {
log.error("Couldn't chain next Job", ex);
return;
}
}
}

问题在

<bean id="completionListener" class="com.dummy.MyListener"/>

你需要给属性名像下面

<bean id="completionListener" class="com.dummy.MyListener">
<property name="myListener" ref="myListener"></property>
</bean>

最新更新