MyBatis中SqlSessionFactoryBean的作用

为什么返回的是SqlSessionFactory对象而不是SqlSessionFactoryBean
首先spring在初始化的时候会将所有创建的单例以Map的形式放入singletonObjects,同时调用FactoryBean的getObject()将返回的对象以Map的形式放入factoryBeanObjectCache

如{sqlSessionFactory=org.apache.ibatis.session.defaults.DefaultSqlSessionFactory@d997f9}

 

然后getBean的时候,spring利用getSingleton从singletonObjects获取单例(这里是SqlSessionFactoryBean对象),判断是否实现了FactoryBean接口,若实现了就从factoryBeanObjectCache利用beanname(这里是sqlSessionFactory)重新获取,若未实现则返回getSingleton获取的单例

 

 

原作者:https://blog.csdn.net/Mask_V/article/details/79368884

你可能感兴趣的:(MyBatis中SqlSessionFactoryBean的作用)