类 ScheduledAnnotationBeanPostProcessor
- java.lang.Object
- org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
- 所有已实现的接口:
EventListener,Aware,BeanFactoryAware,BeanNameAware,BeanPostProcessor,DestructionAwareBeanPostProcessor,DisposableBean,SmartInitializingSingleton,MergedBeanDefinitionPostProcessor,ApplicationContextAware,ApplicationListener<ContextRefreshedEvent>,EmbeddedValueResolverAware,Ordered,ScheduledTaskHolder
public class ScheduledAnnotationBeanPostProcessor extends Object implements ScheduledTaskHolder, MergedBeanDefinitionPostProcessor, DestructionAwareBeanPostProcessor, Ordered, EmbeddedValueResolverAware, BeanNameAware, BeanFactoryAware, ApplicationContextAware, SmartInitializingSingleton, ApplicationListener<ContextRefreshedEvent>, DisposableBean
Bean post-processor that registers methods annotated with @Scheduledto be invoked by aTaskScheduleraccording 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@EnableSchedulingannotation.Autodetects any
SchedulingConfigurerinstances in the container, allowing for customization of the scheduler to be used or for fine-grained control over task registration (e.g. registration ofTriggertasks. See the @EnableSchedulingjavadocs for complete usage details.- 从以下版本开始:
- 3.0
- 作者:
- Mark Fisher, Juergen Hoeller, Chris Beams, Elizabeth Chatman
- 另请参阅:
Scheduled,EnableScheduling,SchedulingConfigurer,TaskScheduler,ScheduledTaskRegistrar,AsyncAnnotationBeanPostProcessor
字段概要
字段 修饰符和类型 字段 说明 static StringDEFAULT_TASK_SCHEDULER_BEAN_NAMEThe default name of theTaskSchedulerbean to pick up: "taskScheduler".protected Loglogger从接口继承的字段 org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
构造器概要
构造器 构造器 说明 ScheduledAnnotationBeanPostProcessor()Create a defaultScheduledAnnotationBeanPostProcessor.ScheduledAnnotationBeanPostProcessor(ScheduledTaskRegistrar registrar)Create aScheduledAnnotationBeanPostProcessordelegating to the specifiedScheduledTaskRegistrar.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterSingletonsInstantiated()Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already.protected RunnablecreateRunnable(Object target, Method method)Create aRunnablefor the given bean instance, calling the specified scheduled method.voiddestroy()Invoked by the containingBeanFactoryon destruction of a bean.intgetOrder()Get the order value of this object.Set<ScheduledTask>getScheduledTasks()Return all currently scheduled tasks, fromScheduledmethods as well as from programmaticSchedulingConfigurerinteraction.voidonApplicationEvent(ContextRefreshedEvent event)Handle an application event.ObjectpostProcessAfterInitialization(Object bean, String beanName)Apply thisBeanPostProcessorto the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method).voidpostProcessBeforeDestruction(Object bean, String beanName)Apply this BeanPostProcessor to the given bean instance before its destruction, e.g. invoking custom destruction callbacks.ObjectpostProcessBeforeInitialization(Object bean, String beanName)Apply thisBeanPostProcessorto the given new bean instance before any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method).voidpostProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName)Post-process the given merged bean definition for the specified bean.protected voidprocessScheduled(Scheduled scheduled, Method method, Object bean)Process the given@Scheduledmethod declaration on the given bean.booleanrequiresDestruction(Object bean)Determine whether the given bean instance requires destruction by this post-processor.voidsetApplicationContext(ApplicationContext applicationContext)Setting anApplicationContextis optional: If set, registered tasks will be activated in theContextRefreshedEventphase; if not set, it will happen atafterSingletonsInstantiated()time.voidsetBeanFactory(BeanFactory beanFactory)Making aBeanFactoryavailable is optional; if not set,SchedulingConfigurerbeans won't get autodetected and aschedulerhas to be explicitly configured.voidsetBeanName(String beanName)Set the name of the bean in the bean factory that created this bean.voidsetEmbeddedValueResolver(StringValueResolver resolver)Set the StringValueResolver to use for resolving embedded definition values.voidsetScheduler(Object scheduler)Set theTaskSchedulerthat will invoke the scheduled methods, or aScheduledExecutorServiceto be wrapped as a TaskScheduler.从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
从接口继承的方法 org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor
resetBeanDefinition
字段详细资料
DEFAULT_TASK_SCHEDULER_BEAN_NAME
public static final String DEFAULT_TASK_SCHEDULER_BEAN_NAME
The default name of theTaskSchedulerbean 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.
- 从以下版本开始:
- 4.2
- 另请参阅:
- 常量字段值
构造器详细资料
ScheduledAnnotationBeanPostProcessor
public ScheduledAnnotationBeanPostProcessor()
Create a defaultScheduledAnnotationBeanPostProcessor.
ScheduledAnnotationBeanPostProcessor
public ScheduledAnnotationBeanPostProcessor(ScheduledTaskRegistrar registrar)
Create aScheduledAnnotationBeanPostProcessordelegating to the specifiedScheduledTaskRegistrar.- 参数:
registrar- the ScheduledTaskRegistrar to register @Scheduled tasks on- 从以下版本开始:
- 5.1
方法详细资料
getOrder
public int getOrder()
从接口复制的说明:OrderedGet the order value of this object.Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet
load-on-startupvalues).Same order values will result in arbitrary sort positions for the affected objects.
- 指定者:
getOrder在接口中Ordered- 返回:
- the order value
- 另请参阅:
Ordered.HIGHEST_PRECEDENCE,Ordered.LOWEST_PRECEDENCE
setScheduler
public void setScheduler(Object scheduler)
Set theTaskSchedulerthat will invoke the scheduled methods, or aScheduledExecutorServiceto be wrapped as a TaskScheduler.If not specified, default scheduler resolution will apply: searching for a unique
TaskSchedulerbean in the context, or for aTaskSchedulerbean named "taskScheduler" otherwise; the same lookup will also be performed for aScheduledExecutorServicebean. If neither of the two is resolvable, a local single-threaded default scheduler will be created within the registrar.
setEmbeddedValueResolver
public void setEmbeddedValueResolver(StringValueResolver resolver)
从接口复制的说明:EmbeddedValueResolverAwareSet the StringValueResolver to use for resolving embedded definition values.
setBeanName
public void setBeanName(String beanName)
从接口复制的说明:BeanNameAwareSet the name of the bean in the bean factory that created this bean.Invoked after population of normal bean properties but before an init callback such as
InitializingBean.afterPropertiesSet()or a custom init-method.- 指定者:
setBeanName在接口中BeanNameAware- 参数:
beanName- the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use theBeanFactoryUtils.originalBeanName(String)method to extract the original bean name (without suffix), if desired.
setBeanFactory
public void setBeanFactory(BeanFactory beanFactory)
Making aBeanFactoryavailable is optional; if not set,SchedulingConfigurerbeans won't get autodetected and aschedulerhas to be explicitly configured.- 指定者:
setBeanFactory在接口中BeanFactoryAware- 参数:
beanFactory- owning BeanFactory (nevernull). The bean can immediately call methods on the factory.- 另请参阅:
BeanInitializationException
setApplicationContext
public void setApplicationContext(ApplicationContext applicationContext)
Setting anApplicationContextis optional: If set, registered tasks will be activated in theContextRefreshedEventphase; if not set, it will happen atafterSingletonsInstantiated()time.- 指定者:
setApplicationContext在接口中ApplicationContextAware- 参数:
applicationContext- the ApplicationContext object to be used by this object- 另请参阅:
BeanInitializationException
afterSingletonsInstantiated
public void afterSingletonsInstantiated()
从接口复制的说明:SmartInitializingSingletonInvoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already.ListableBeanFactory.getBeansOfType(java.lang.Class<T>)calls within this method won't trigger accidental side effects during bootstrap.NOTE: This callback won't be triggered for singleton beans lazily initialized on demand after
BeanFactorybootstrap, and not for any other bean scope either. Carefully use it for beans with the intended bootstrap semantics only.
onApplicationEvent
public void onApplicationEvent(ContextRefreshedEvent event)
从接口复制的说明:ApplicationListenerHandle an application event.- 指定者:
onApplicationEvent在接口中ApplicationListener<ContextRefreshedEvent>- 参数:
event- the event to respond to
postProcessMergedBeanDefinition
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName)
从接口复制的说明:MergedBeanDefinitionPostProcessorPost-process the given merged bean definition for the specified bean.- 指定者:
postProcessMergedBeanDefinition在接口中MergedBeanDefinitionPostProcessor- 参数:
beanDefinition- the merged bean definition for the beanbeanType- the actual type of the managed bean instancebeanName- the name of the bean- 另请参阅:
AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Class<?>, java.lang.String)
postProcessBeforeInitialization
public Object postProcessBeforeInitialization(Object bean, String beanName)
从接口复制的说明:BeanPostProcessorApply thisBeanPostProcessorto the given new bean instance before any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.The default implementation returns the given
beanas-is.- 指定者:
postProcessBeforeInitialization在接口中BeanPostProcessor- 参数:
bean- the new bean instancebeanName- the name of the bean- 返回:
- the bean instance to use, either the original or a wrapped one; if
null, no subsequent BeanPostProcessors will be invoked - 另请参阅:
InitializingBean.afterPropertiesSet()
postProcessAfterInitialization
public Object postProcessAfterInitialization(Object bean, String beanName)
从接口复制的说明:BeanPostProcessorApply thisBeanPostProcessorto the given new bean instance after any bean initialization callbacks (like InitializingBean'safterPropertiesSetor a custom init-method). The bean will already be populated with property values. The returned bean instance may be a wrapper around the original.In case of a FactoryBean, this callback will be invoked for both the FactoryBean instance and the objects created by the FactoryBean (as of Spring 2.0). The post-processor can decide whether to apply to either the FactoryBean or created objects or both through corresponding
bean instanceof FactoryBeanchecks.This callback will also be invoked after a short-circuiting triggered by a
InstantiationAwareBeanPostProcessor.postProcessBeforeInstantiation(java.lang.Class<?>, java.lang.String)method, in contrast to all otherBeanPostProcessorcallbacks.The default implementation returns the given
beanas-is.- 指定者:
postProcessAfterInitialization在接口中BeanPostProcessor- 参数:
bean- the new bean instancebeanName- the name of the bean- 返回:
- the bean instance to use, either the original or a wrapped one; if
null, no subsequent BeanPostProcessors will be invoked - 另请参阅:
InitializingBean.afterPropertiesSet(),FactoryBean
processScheduled
protected void processScheduled(Scheduled scheduled, Method method, Object bean)
Process the given@Scheduledmethod declaration on the given bean.- 参数:
scheduled- the @Scheduled annotationmethod- the method that the annotation has been declared onbean- the target bean instance- 另请参阅:
createRunnable(Object, Method)
createRunnable
protected Runnable createRunnable(Object target, Method method)
Create aRunnablefor the given bean instance, calling the specified scheduled method.The default implementation creates a
ScheduledMethodRunnable.- 参数:
target- the target bean instancemethod- the scheduled method to call- 从以下版本开始:
- 5.1
- 另请参阅:
ScheduledMethodRunnable(Object, Method)
getScheduledTasks
public Set<ScheduledTask> getScheduledTasks()
Return all currently scheduled tasks, fromScheduledmethods as well as from programmaticSchedulingConfigurerinteraction.- 指定者:
getScheduledTasks在接口中ScheduledTaskHolder- 从以下版本开始:
- 5.0.2
postProcessBeforeDestruction
public void postProcessBeforeDestruction(Object bean, String beanName)
从接口复制的说明:DestructionAwareBeanPostProcessorApply this BeanPostProcessor to the given bean instance before its destruction, e.g. invoking custom destruction callbacks.Like DisposableBean's
destroyand a custom destroy method, this callback will only apply to beans which the container fully manages the lifecycle for. This is usually the case for singletons and scoped beans.- 指定者:
postProcessBeforeDestruction在接口中DestructionAwareBeanPostProcessor- 参数:
bean- the bean instance to be destroyedbeanName- the name of the bean- 另请参阅:
DisposableBean.destroy(),AbstractBeanDefinition.setDestroyMethodName(String)
requiresDestruction
public boolean requiresDestruction(Object bean)
从接口复制的说明:DestructionAwareBeanPostProcessorDetermine whether the given bean instance requires destruction by this post-processor.The default implementation returns
true. If a pre-5 implementation ofDestructionAwareBeanPostProcessordoes not provide a concrete implementation of this method, Spring silently assumestrueas well.- 指定者:
requiresDestruction在接口中DestructionAwareBeanPostProcessor- 参数:
bean- the bean instance to check- 返回:
trueifDestructionAwareBeanPostProcessor.postProcessBeforeDestruction(java.lang.Object, java.lang.String)is supposed to be called for this bean instance eventually, orfalseif not needed
destroy
public void destroy()
从接口复制的说明:DisposableBeanInvoked by the containingBeanFactoryon destruction of a bean.- 指定者:
destroy在接口中DisposableBean