Interface SmartInitializingSingleton
- All Known Implementing Classes:
AnnotationMBeanExporter,CacheAspectSupport,CacheInterceptor,CacheProxyFactoryBean,ContextLifecycleScheduledTaskRegistrar,DefaultJCacheOperationSource,EventListenerMethodProcessor,JmsListenerAnnotationBeanPostProcessor,MBeanExporter,ScheduledAnnotationBeanPostProcessor,ServerEndpointExporter
public interface SmartInitializingSingleton
Callback interface triggered at the end of the singleton pre-instantiation phase duringBeanFactorybootstrap. This interface can be implemented by singleton beans in order to perform some initialization after the regular singleton instantiation algorithm, avoiding side effects with accidental early initialization (e.g. fromListableBeanFactory.getBeansOfType(java.lang.Class<T>)calls). In that sense, it is an alternative toInitializingBeanwhich gets triggered right at the end of a bean's local construction phase.This callback variant is somewhat similar to
ContextRefreshedEventbut doesn't require an implementation ofApplicationListener, with no need to filter context references across a context hierarchy etc. It also implies a more minimal dependency on just thebeanspackage and is being honored by standaloneListableBeanFactoryimplementations, not just in anApplicationContextenvironment.NOTE: If you intend to start/manage asynchronous tasks, preferably implement
Lifecycleinstead which offers a richer model for runtime management and allows for phased startup/shutdown.- Since:
- 4.1
- Author:
- Juergen Hoeller
- See Also:
ConfigurableListableBeanFactory.preInstantiateSingletons()
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidafterSingletonsInstantiated()Invoked right at the end of the singleton pre-instantiation phase, with a guarantee that all regular singleton beans have been created already.
Method Detail
afterSingletonsInstantiated
void afterSingletonsInstantiated()
Invoked 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.