Class ScheduledAnnotationBeanPostProcessor
- All Implemented Interfaces:
EventListener
,org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.BeanNameAware
,org.springframework.beans.factory.config.BeanPostProcessor
,org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.SmartInitializingSingleton
,org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
,ApplicationContextAware
,ApplicationListener<ContextRefreshedEvent>
,EmbeddedValueResolverAware
,org.springframework.core.Ordered
,ScheduledTaskHolder
@Scheduled
to be invoked by a
TaskScheduler
according to the
"fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
This post-processor is automatically registered by Spring's
<task:annotation-driven>
XML element and also by the
@EnableScheduling
annotation.
Autodetects any SchedulingConfigurer
instances in the container,
allowing for customization of the scheduler to be used or for fine-grained
control over task registration (e.g. registration of Trigger
tasks).
See the @EnableScheduling
javadocs for complete usage
details.
- Since:
- 3.0
- Author:
- Mark Fisher, Juergen Hoeller, Chris Beams, Elizabeth Chatman, Victor Brown, Sam Brannen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The default name of theTaskScheduler
bean to pick up: "taskScheduler".protected final org.apache.commons.logging.Log
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a defaultScheduledAnnotationBeanPostProcessor
.Create aScheduledAnnotationBeanPostProcessor
delegating to the specifiedScheduledTaskRegistrar
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
protected Runnable
createRunnable
(Object target, Method method) Create aRunnable
for the given bean instance, calling the specified scheduled method.void
destroy()
int
getOrder()
Return all currently scheduled tasks, fromScheduled
methods as well as from programmaticSchedulingConfigurer
interaction.void
Handle an application event.postProcessAfterInitialization
(Object bean, String beanName) void
postProcessBeforeDestruction
(Object bean, String beanName) postProcessBeforeInitialization
(Object bean, String beanName) void
postProcessMergedBeanDefinition
(org.springframework.beans.factory.support.RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) protected void
processScheduled
(Scheduled scheduled, Method method, Object bean) Process the given@Scheduled
method declaration on the given bean.boolean
requiresDestruction
(Object bean) void
setApplicationContext
(ApplicationContext applicationContext) Setting anApplicationContext
is optional: If set, registered tasks will be activated in theContextRefreshedEvent
phase; if not set, it will happen atafterSingletonsInstantiated()
time.void
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory) Making aBeanFactory
available is optional; if not set,SchedulingConfigurer
beans won't get autodetected and ascheduler
has to be explicitly configured.void
setBeanName
(String beanName) void
setEmbeddedValueResolver
(org.springframework.util.StringValueResolver resolver) Set the StringValueResolver to use for resolving embedded definition values.void
setScheduler
(Object scheduler) Set theTaskScheduler
that will invoke the scheduled methods, or aScheduledExecutorService
to be wrapped as a TaskScheduler.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
resetBeanDefinition
-
Field Details
-
DEFAULT_TASK_SCHEDULER_BEAN_NAME
The default name of theTaskScheduler
bean to pick up: "taskScheduler".Note that the initial lookup happens by type; this is just the fallback in case of multiple scheduler beans found in the context.
- Since:
- 4.2
- See Also:
-
logger
protected final org.apache.commons.logging.Log logger
-
-
Constructor Details
-
ScheduledAnnotationBeanPostProcessor
public ScheduledAnnotationBeanPostProcessor()Create a defaultScheduledAnnotationBeanPostProcessor
. -
ScheduledAnnotationBeanPostProcessor
Create aScheduledAnnotationBeanPostProcessor
delegating to the specifiedScheduledTaskRegistrar
.- Parameters:
registrar
- the ScheduledTaskRegistrar to register@Scheduled
tasks on- Since:
- 5.1
-
-
Method Details
-
getOrder
public int getOrder()- Specified by:
getOrder
in interfaceorg.springframework.core.Ordered
-
setScheduler
Set theTaskScheduler
that will invoke the scheduled methods, or aScheduledExecutorService
to be wrapped as a TaskScheduler.If not specified, default scheduler resolution will apply: searching for a unique
TaskScheduler
bean in the context, or for aTaskScheduler
bean named "taskScheduler" otherwise; the same lookup will also be performed for aScheduledExecutorService
bean. If neither of the two is resolvable, a local single-threaded default scheduler will be created within the registrar.- See Also:
-
setEmbeddedValueResolver
public void setEmbeddedValueResolver(org.springframework.util.StringValueResolver resolver) Description copied from interface:EmbeddedValueResolverAware
Set the StringValueResolver to use for resolving embedded definition values.- Specified by:
setEmbeddedValueResolver
in interfaceEmbeddedValueResolverAware
-
setBeanName
- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) Making aBeanFactory
available is optional; if not set,SchedulingConfigurer
beans won't get autodetected and ascheduler
has to be explicitly configured.- Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
-
setApplicationContext
Setting anApplicationContext
is optional: If set, registered tasks will be activated in theContextRefreshedEvent
phase; if not set, it will happen atafterSingletonsInstantiated()
time.- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Parameters:
applicationContext
- the ApplicationContext object to be used by this object- See Also:
-
BeanInitializationException
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiated
in interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
onApplicationEvent
Description copied from interface:ApplicationListener
Handle an application event.- Specified by:
onApplicationEvent
in interfaceApplicationListener<ContextRefreshedEvent>
- Parameters:
event
- the event to respond to
-
postProcessMergedBeanDefinition
public void postProcessMergedBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) - Specified by:
postProcessMergedBeanDefinition
in interfaceorg.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
-
postProcessBeforeInitialization
- Specified by:
postProcessBeforeInitialization
in interfaceorg.springframework.beans.factory.config.BeanPostProcessor
-
postProcessAfterInitialization
- Specified by:
postProcessAfterInitialization
in interfaceorg.springframework.beans.factory.config.BeanPostProcessor
-
processScheduled
Process the given@Scheduled
method declaration on the given bean.- Parameters:
scheduled
- the@Scheduled
annotationmethod
- the method that the annotation has been declared onbean
- the target bean instance- See Also:
-
createRunnable
Create aRunnable
for the given bean instance, calling the specified scheduled method.The default implementation creates a
ScheduledMethodRunnable
.- Parameters:
target
- the target bean instancemethod
- the scheduled method to call- Since:
- 5.1
- See Also:
-
getScheduledTasks
Return all currently scheduled tasks, fromScheduled
methods as well as from programmaticSchedulingConfigurer
interaction.- Specified by:
getScheduledTasks
in interfaceScheduledTaskHolder
- Since:
- 5.0.2
-
postProcessBeforeDestruction
- Specified by:
postProcessBeforeDestruction
in interfaceorg.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
-
requiresDestruction
- Specified by:
requiresDestruction
in interfaceorg.springframework.beans.factory.config.DestructionAwareBeanPostProcessor
-
destroy
public void destroy()- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-