001/* 002 * Copyright 2002-2012 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 * Extension of the {@link FactoryBean} interface. Implementations may 021 * indicate whether they always return independent instances, for the 022 * case where their {@link #isSingleton()} implementation returning 023 * {@code false} does not clearly indicate independent instances. 024 * 025 * <p>Plain {@link FactoryBean} implementations which do not implement 026 * this extended interface are simply assumed to always return independent 027 * instances if their {@link #isSingleton()} implementation returns 028 * {@code false}; the exposed object is only accessed on demand. 029 * 030 * <p><b>NOTE:</b> This interface is a special purpose interface, mainly for 031 * internal use within the framework and within collaborating frameworks. 032 * In general, application-provided FactoryBeans should simply implement 033 * the plain {@link FactoryBean} interface. New methods might be added 034 * to this extended interface even in point releases. 035 * 036 * @author Juergen Hoeller 037 * @since 2.0.3 038 * @see #isPrototype() 039 * @see #isSingleton() 040 */ 041public interface SmartFactoryBean<T> extends FactoryBean<T> { 042 043 /** 044 * Is the object managed by this factory a prototype? That is, 045 * will {@link #getObject()} always return an independent instance? 046 * <p>The prototype status of the FactoryBean itself will generally 047 * be provided by the owning {@link BeanFactory}; usually, it has to be 048 * defined as singleton there. 049 * <p>This method is supposed to strictly check for independent instances; 050 * it should not return {@code true} for scoped objects or other 051 * kinds of non-singleton, non-independent objects. For this reason, 052 * this is not simply the inverted form of {@link #isSingleton()}. 053 * @return whether the exposed object is a prototype 054 * @see #getObject() 055 * @see #isSingleton() 056 */ 057 boolean isPrototype(); 058 059 /** 060 * Does this FactoryBean expect eager initialization, that is, 061 * eagerly initialize itself as well as expect eager initialization 062 * of its singleton object (if any)? 063 * <p>A standard FactoryBean is not expected to initialize eagerly: 064 * Its {@link #getObject()} will only be called for actual access, even 065 * in case of a singleton object. Returning {@code true} from this 066 * method suggests that {@link #getObject()} should be called eagerly, 067 * also applying post-processors eagerly. This may make sense in case 068 * of a {@link #isSingleton() singleton} object, in particular if 069 * post-processors expect to be applied on startup. 070 * @return whether eager initialization applies 071 * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory#preInstantiateSingletons() 072 */ 073 boolean isEagerInit(); 074 075}