001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.beans.factory; 018 019/** 020 * Callback interface triggered at the end of the singleton pre-instantiation phase 021 * during {@link BeanFactory} bootstrap. This interface can be implemented by 022 * singleton beans in order to perform some initialization after the regular 023 * singleton instantiation algorithm, avoiding side effects with accidental early 024 * initialization (e.g. from {@link ListableBeanFactory#getBeansOfType} calls). 025 * In that sense, it is an alternative to {@link InitializingBean} which gets 026 * triggered right at the end of a bean's local construction phase. 027 * 028 * <p>This callback variant is somewhat similar to 029 * {@link org.springframework.context.event.ContextRefreshedEvent} but doesn't 030 * require an implementation of {@link org.springframework.context.ApplicationListener}, 031 * with no need to filter context references across a context hierarchy etc. 032 * It also implies a more minimal dependency on just the {@code beans} package 033 * and is being honored by standalone {@link ListableBeanFactory} implementations, 034 * not just in an {@link org.springframework.context.ApplicationContext} environment. 035 * 036 * <p><b>NOTE:</b> If you intend to start/manage asynchronous tasks, preferably 037 * implement {@link org.springframework.context.Lifecycle} instead which offers 038 * a richer model for runtime management and allows for phased startup/shutdown. 039 * 040 * @author Juergen Hoeller 041 * @since 4.1 042 * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory#preInstantiateSingletons() 043 */ 044public interface SmartInitializingSingleton { 045 046 /** 047 * Invoked right at the end of the singleton pre-instantiation phase, 048 * with a guarantee that all regular singleton beans have been created 049 * already. {@link ListableBeanFactory#getBeansOfType} calls within 050 * this method won't trigger accidental side effects during bootstrap. 051 * <p><b>NOTE:</b> This callback won't be triggered for singleton beans 052 * lazily initialized on demand after {@link BeanFactory} bootstrap, 053 * and not for any other bean scope either. Carefully use it for beans 054 * with the intended bootstrap semantics only. 055 */ 056 void afterSingletonsInstantiated(); 057 058}