我的AlbumOperateDaoImpl extends HibernateDaoSupport,spring在检查时找不到sessionFactory,因此在配置文件中添加如下代码:
<bean id="albumOperateDaoImpl" class="org.huang.persistence.hibernate.AlbumOperateDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean>
注意配置文件中以下代码存在!
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> </props> </property> </bean>
如果用注解方式,则在AlbumOperateDaoImpl中添加如下代码:
@Resource public void setSessionFacotry(SessionFactory sessionFacotry) { super.setSessionFactory(sessionFacotry); }
换言之,
<bean id="albumOperateDaoImpl" class="org.huang.persistence.hibernate.AlbumOperateDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean>
与
@Resource public void setSessionFacotry(SessionFactory sessionFacotry) { super.setSessionFactory(sessionFacotry); }
是等价的。