spring 配置:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
......
java代码:
SessionFactiory sessionFactiory = (SessionFactiory )ctx.getBean("sessionFactory");
问题:
今天看了下AnnotationSessionFactoryBean的源码,里面竟然没有实现SessionFactory接口,
请问它是如何赋值给SessionFactory的?
望高手解答问题!
------解决思路----------------------
是的,new AnnotationSessionFactoryBean() instanceof SessionFactory 是false
因为
首先看继承
AnnotationSessionFactoryBean extends LocalSessionFactoryBean extends AbstractSessionFactoryBean implements
FactoryBean<SessionFactory>
实现FactoryBean接口的类,通过getBean()方法时,返回的并不是bean定义的对象,而是getObject()返回的对象
而
AbstractSessionFactoryBean类实现了getObject()方法 返回的是SessionFactory
关键看getObject()方法