SchedulerAccessorBean falls back to finding a default Scheduler bean by type
Issue: SPR-12094
This commit is contained in:
parent
2ef3d66c89
commit
a2e6b56dd0
|
@ -46,20 +46,24 @@ public class SchedulerAccessorBean extends SchedulerAccessor implements BeanFact
|
|||
|
||||
|
||||
/**
|
||||
* Specify the Quartz Scheduler to operate on via its scheduler name in the Spring
|
||||
* Specify the Quartz {@link Scheduler} to operate on via its scheduler name in the Spring
|
||||
* application context or also in the Quartz {@link org.quartz.impl.SchedulerRepository}.
|
||||
* <p>Schedulers can be registered in the repository through custom bootstrapping,
|
||||
* e.g. via the {@link org.quartz.impl.StdSchedulerFactory} or
|
||||
* {@link org.quartz.impl.DirectSchedulerFactory} factory classes.
|
||||
* However, in general, it's preferable to use Spring's {@link SchedulerFactoryBean}
|
||||
* which includes the job/trigger/listener capabilities of this accessor as well.
|
||||
* <p>If not specified, this accessor will try to retrieve a default {@link Scheduler}
|
||||
* bean from the containing application context.
|
||||
*/
|
||||
public void setSchedulerName(String schedulerName) {
|
||||
this.schedulerName = schedulerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the Quartz Scheduler instance to operate on.
|
||||
* Specify the Quartz {@link Scheduler} instance to operate on.
|
||||
* <p>If not specified, this accessor will try to retrieve a default {@link Scheduler}
|
||||
* bean from the containing application context.
|
||||
*/
|
||||
public void setScheduler(Scheduler scheduler) {
|
||||
this.scheduler = scheduler;
|
||||
|
@ -82,12 +86,7 @@ public class SchedulerAccessorBean extends SchedulerAccessor implements BeanFact
|
|||
@Override
|
||||
public void afterPropertiesSet() throws SchedulerException {
|
||||
if (this.scheduler == null) {
|
||||
if (this.schedulerName != null) {
|
||||
this.scheduler = findScheduler(this.schedulerName);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("No Scheduler specified");
|
||||
}
|
||||
this.scheduler = (this.schedulerName != null ? findScheduler(this.schedulerName) : findDefaultScheduler());
|
||||
}
|
||||
registerListeners();
|
||||
registerJobsAndTriggers();
|
||||
|
@ -111,4 +110,14 @@ public class SchedulerAccessorBean extends SchedulerAccessor implements BeanFact
|
|||
return schedulerInRepo;
|
||||
}
|
||||
|
||||
protected Scheduler findDefaultScheduler() {
|
||||
if (this.beanFactory != null) {
|
||||
return this.beanFactory.getBean(Scheduler.class);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException(
|
||||
"No Scheduler specified, and cannot find a default Scheduler without a BeanFactory");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"/>
|
||||
|
||||
<bean class="org.springframework.scheduling.quartz.SchedulerAccessorBean">
|
||||
<property name="scheduler" ref="scheduler"/>
|
||||
<property name="triggers">
|
||||
<list>
|
||||
<ref local="exportTrigger"/>
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
<property name="exposeSchedulerInRepository" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean id="otherScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
|
||||
<property name="schedulerName" value="otherScheduler"/>
|
||||
</bean>
|
||||
|
||||
<bean class="org.springframework.scheduling.quartz.SchedulerAccessorBean">
|
||||
<property name="schedulerName" value="myScheduler"/>
|
||||
<property name="triggers">
|
||||
|
|
Loading…
Reference in New Issue