spring-framework / org.springframework.beans.factory / SmartInitializingSingleton

SmartInitializingSingleton

interface SmartInitializingSingleton

Callback interface triggered at the end of the singleton pre-instantiation phase during BeanFactory bootstrap. 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. from ListableBeanFactory#getBeansOfType calls). In that sense, it is an alternative to InitializingBean which gets triggered right at the end of a bean's local construction phase.

This callback variant is somewhat similar to org.springframework.context.event.ContextRefreshedEvent but doesn't require an implementation of org.springframework.context.ApplicationListener, with no need to filter context references across a context hierarchy etc. It also implies a more minimal dependency on just the beans package and is being honored by standalone ListableBeanFactory implementations, not just in an org.springframework.context.ApplicationContext environment.

NOTE: If you intend to start/manage asynchronous tasks, preferably implement org.springframework.context.Lifecycle instead which offers a richer model for runtime management and allows for phased startup/shutdown.

Author
Juergen Hoeller

Since
4.1

See Also
org.springframework.beans.factory.config.ConfigurableListableBeanFactory#preInstantiateSingletons()

Functions

afterSingletonsInstantiated

abstract fun afterSingletonsInstantiated(): Unit

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 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 BeanFactory bootstrap, and not for any other bean scope either. Carefully use it for beans with the intended bootstrap semantics only.

Inheritors

CacheAspectSupport

abstract class CacheAspectSupport : AbstractCacheInvoker, BeanFactoryAware, InitializingBean, SmartInitializingSingleton

Base class for caching aspects, such as the CacheInterceptor or an AspectJ aspect.

This enables the underlying Spring caching infrastructure to be used easily to implement an aspect for any aspect system.

Subclasses are responsible for calling methods in this class in the correct order.

Uses the Strategy design pattern. A CacheResolver implementation will resolve the actual cache(s) to use, and a CacheOperationSource is used for determining caching operations.

A cache aspect is serializable if its CacheResolver and CacheOperationSource are serializable.

ContextLifecycleScheduledTaskRegistrar

open class ContextLifecycleScheduledTaskRegistrar : ScheduledTaskRegistrar, SmartInitializingSingleton

ScheduledTaskRegistrar subclass which redirects the actual scheduling of tasks to the #afterSingletonsInstantiated() callback (as of 4.1.2).

DefaultJCacheOperationSource

open class DefaultJCacheOperationSource : AnnotationJCacheOperationSource, BeanFactoryAware, InitializingBean, SmartInitializingSingleton

The default JCacheOperationSource implementation delegating default operations to configurable services with sensible defaults when not present.

EventListenerMethodProcessor

open class EventListenerMethodProcessor : SmartInitializingSingleton, ApplicationContextAware

Register EventListener annotated method as individual ApplicationListener instances.

JmsListenerAnnotationBeanPostProcessor

open class JmsListenerAnnotationBeanPostProcessor : MergedBeanDefinitionPostProcessor, Ordered, BeanFactoryAware, SmartInitializingSingleton

Bean post-processor that registers methods annotated with JmsListener to be invoked by a JMS message listener container created under the cover by a org.springframework.jms.config.JmsListenerContainerFactory according to the attributes of the annotation.

Annotated methods can use flexible arguments as defined by JmsListener.

This post-processor is automatically registered by Spring's <jms:annotation-driven> XML element, and also by the EnableJms annotation.

Autodetects any JmsListenerConfigurer instances in the container, allowing for customization of the registry to be used, the default container factory or for fine-grained control over endpoints registration. See the EnableJms javadocs for complete usage details.

ServerEndpointExporter

open class ServerEndpointExporter : WebApplicationObjectSupport, InitializingBean, SmartInitializingSingleton

Detects beans of type javax.websocket.server.ServerEndpointConfig and registers with the standard Java WebSocket runtime. Also detects beans annotated with ServerEndpoint and registers them as well. Although not required, it is likely annotated endpoints should have their configurator property set to SpringConfigurator.

When this class is used, by declaring it in Spring configuration, it should be possible to turn off a Servlet container's scan for WebSocket endpoints. This can be done with the help of the <absolute-ordering> element in web.xml.