ObjectFactory和FactoryBean区别
应用场景
/** Cache of singleton objects: bean name to bean instance. */ private final Map<String, Object> singletonObjects = new ConcurrentHashMap<>(256);
/** Cache of singleton factories: bean name to ObjectFactory. */
//第三级缓存运用了ObjectFactory
private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap<>(16);
/** Cache of early singleton objects: bean name to bean instance. */
private final Map<String, Object> earlySingletonObjects = new HashMap<>(16);
FactorBean
public interface FactoryBean<T> { @Nullable
T getObject() throws Exception;
@Nullable
Class<?> getObjectType();
default boolean isSingleton() {
return true;
}
}
由BeanFactory中使用的对象实现的接口,这些对象本身就是各个对象的工厂。如果一个bean实现了这个接口,那么它将被用作要公开的对象的工厂,而不是直接用作将自己公开的bean实例。
应用场景
MapperFactoryBean,mybatis通过这个类来生成Mapper对象
区别
两个类都是对象工厂,用来产生对象。FactoryBean更加专业些,而ObjectFactory只是个普通的对象工厂
参照
- https://blog.csdn.net/m0_38043362/article/details/80284577
以上是 ObjectFactory和FactoryBean区别 的全部内容, 来源链接: utcz.com/z/515025.html