public class ContextLifecycleScheduledTaskRegistrar extends ScheduledTaskRegistrar implements ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>
ScheduledTaskRegistrar
subclass that redirects the actual scheduling
of tasks to the ContextRefreshedEvent
callback. Falls back to regular
ScheduledTaskRegistrar
behavior when not running within an ApplicationContext.Constructor and Description |
---|
ContextLifecycleScheduledTaskRegistrar() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
If we're running within an ApplicationContext, don't schedule the tasks
right here; wait for this context's ContextRefreshedEvent instead.
|
void |
onApplicationEvent(ContextRefreshedEvent event)
Actually schedule the tasks at the right time of the context lifecycle,
if we're running within an ApplicationContext.
|
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
addCronTask, addCronTask, addFixedDelayTask, addFixedDelayTask, addFixedRateTask, addFixedRateTask, addTriggerTask, addTriggerTask, destroy, getScheduler, hasTasks, scheduleTasks, setCronTasks, setCronTasksList, setFixedDelayTasks, setFixedDelayTasksList, setFixedRateTasks, setFixedRateTasksList, setScheduler, setTaskScheduler, setTriggerTasks, setTriggerTasksList
public ContextLifecycleScheduledTaskRegistrar()
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectBeanInitializationException
public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
afterPropertiesSet
in class ScheduledTaskRegistrar
public void onApplicationEvent(ContextRefreshedEvent event)
onApplicationEvent
in interface ApplicationListener<ContextRefreshedEvent>
event
- the event to respond to