ObjectFactory和BeanFactory

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章