[html]
< xml version="1.0" encoding="UTF-8" >
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
——————————————————————————
< xml version="1.0" encoding="UTF-8" >
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
——————————————————————————
问:
org.springframework.orm.hibernate3.LocalSessionFactoryBean;
这个类型根本没有getCurrentSession的方法。
而productDAO中的sessionFactory是org.hibernate.SessionFactory,这中间的类型是怎么转换的啊?
试了一下往数据库保存是成功的,就是想不通这个类型的转换,我看LocalSessionFactoryBean也没有实现SessionFactory这个接口啊 www.2cto.com
难道是LocalSessionFactoryBean的getObject()方法
答:
正是如此!LocalSessionFactoryBean实现了org.springframework.beans.factory.FactoryBean接口, spring在装配的时候, 如果发现实现了org.springframework.beans.factory.FactoryBean接口, 就会使用FactoryBean#getObject() 方法返回的对象装配,具体的可以看下文档.
如果你想拿到LocalSessionFactoryBean实例, 在id前面加个'&'就可以了,在你的配置文件中BeanFactory.getBean('&sessionFactory')拿到的就是LocalSessionFactoryBean的实例.
作者:Tender001