package org.springframework.beans.factory;
/**
* 如果一个类实现了该接口,则这个类是一个具体工厂类,这个具体工厂类是用来生成类型为T的bean。
*
* If a bean implements this interface, it is used as a factory for an object to expose, not directly as a bean instance that will be exposed itself.
*
* FactoryBeans can support singletons and prototypes, and can either create objects lazily on demand or eagerly on startup.
*/
public interface FactoryBean<T> {
/**
* 获取一个类型为T的bean
*
* Return an instance (possibly shared or independent) of the object managed by this factory.
* <p>As with a {@link BeanFactory}, this allows support for both the Singleton and Prototype design pattern.
*/
T getObject() throws Exception;
/**
* Return the type of object that this FactoryBean creates, or {@code null} if not known in advance.
* <p>This allows one to check for specific types of beans without instantiating objects, for example on autowiring.
*/
Class<?> getObjectType();
/**
* Is the object managed by this factory a singleton? That is, will {@link #getObject()} always return the same object
*/
boolean isSingleton();
}
Spring中的FactoryBean
最新推荐文章于 2024-07-31 20:24:04 发布