ObjectFactory
org.springframework.beans.factory.ObjectFactory
定义在调用时可以返回对象实例(可能是共享的或独立的)的工厂。
此接口通常用于封装在每次调用时返回某个目标对象的新实例(原型)的通用工厂。
这个接口类似于FactoryBean,但是后者的实现通常被定义为bean工厂中的SPI实例,而这个类的实现通常被作为API提供给其他bean(通过注入)。因此,getObject()方法具有不同的异常处理行为。
public interface ObjectFactory<T> {
/**
* Return an instance (possibly shared or independent)
* of the object managed by this factory.
* @return the resulting instance
* @throws BeansException in case of creation errors
*/
T getObject() throws BeansException;
}
ObjectProvider
public interface ObjectProvider<T> extends ObjectFactory<T>
FactoryBean
public interface SmartFactoryBean extends FactoryBean