Interface SmartFactoryBean<T>
- Type Parameters:
T- the bean type
- All Superinterfaces:
FactoryBean<T>
- All Known Implementing Classes:
AbstractEntityManagerFactoryBean, LocalContainerEntityManagerFactoryBean, LocalEntityManagerFactoryBean, LocalSessionFactoryBean
FactoryBean interface. Implementations may
indicate whether they always return independent instances, for the
case where their FactoryBean.isSingleton() implementation returning
false does not clearly indicate independent instances.
Plain FactoryBean implementations which do not implement
this extended interface are simply assumed to always return independent
instances if their FactoryBean.isSingleton() implementation returns
false; the exposed object is only accessed on demand.
As of 7.0, this interface also allows for exposing additional object
types for dependency injection through implementing a pair of methods:
getObject(Class) as well as supportsType(Class).
The primary FactoryBean.getObjectType() will be exposed for regular access;
only if a specific type is requested, additional types are considered.
The container will not cache SmartFactoryBean-produced objects;
make sure that the getObject implementation is thread-safe for
repeated invocations.
NOTE: This interface is a special purpose interface, mainly for
internal use within the framework and within collaborating frameworks.
In general, application-provided FactoryBeans should simply implement
the plain FactoryBean interface. New methods might be added
to this extended interface even in point releases.
- Since:
- 2.0.3
- Author:
- Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface FactoryBean
OBJECT_TYPE_ATTRIBUTE -
Method Summary
Modifier and TypeMethodDescriptiondefault <S> @Nullable SReturn an instance of the given type, if supported by this factory.default booleanDoes this FactoryBean expect eager initialization, that is, eagerly initialize itself as well as expect eager initialization of its singleton object (if any)?default booleanIs the object managed by this factory a prototype? That is, willFactoryBean.getObject()always return an independent instance?default booleansupportsType(Class<?> type) Determine whether this factory supports the requested type.Methods inherited from interface FactoryBean
getObject, getObjectType, isSingleton
-
Method Details
-
getObject
Return an instance of the given type, if supported by this factory.By default, this supports the primary type exposed by the factory, as indicated by
FactoryBean.getObjectType()and returned byFactoryBean.getObject(). Specific factories may support additional types for dependency injection.- Parameters:
type- the requested type- Returns:
- a corresponding instance managed by this factory,
or
nullif none available - Throws:
Exception- in case of creation errors- Since:
- 7.0
- See Also:
-
supportsType
Determine whether this factory supports the requested type.By default, this supports the primary type exposed by the factory, as indicated by
FactoryBean.getObjectType(). Specific factories may support additional types for dependency injection.- Parameters:
type- the requested type- Returns:
trueifgetObject(Class)is able to return a corresponding instance,falseotherwise- Since:
- 7.0
- See Also:
-
isPrototype
default boolean isPrototype()Is the object managed by this factory a prototype? That is, willFactoryBean.getObject()always return an independent instance?The prototype status of the FactoryBean itself will generally be provided by the owning
BeanFactory; usually, it has to be defined as singleton there.This method is supposed to strictly check for independent instances; it should not return
truefor scoped objects or other kinds of non-singleton, non-independent objects. For this reason, this is not simply the inverted form ofFactoryBean.isSingleton().The default implementation returns
false.- Returns:
- whether the exposed object is a prototype
- See Also:
-
isEagerInit
default boolean isEagerInit()Does this FactoryBean expect eager initialization, that is, eagerly initialize itself as well as expect eager initialization of its singleton object (if any)?A standard FactoryBean is not expected to initialize eagerly: Its
FactoryBean.getObject()will only be called for actual access, even in case of a singleton object. Returningtruefrom this method suggests thatFactoryBean.getObject()should be called eagerly, also applying post-processors eagerly. This may make sense in case of asingletonobject, in particular if post-processors expect to be applied on startup.The default implementation returns
false.- Returns:
- whether eager initialization applies
- See Also:
-