spring3报错'sessionFactory' or 'hibernateTemplate' is required
整合spring3和hibernate3.6
spring配置:(不用对DAO进行配置)
<context:annotation-config />
<context:component-scan base-package="com.mypack" />//是这行配置为扫描,所以不用对dao进行配置吗?
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
原先的代码:(运行正确)
BaseDao:
public class BaseDao {
protected HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
@Resource
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
}
ExpertDao:
@Component("expertDao")//这行什么意思?
public class ExpertDao extends BaseDao {
//用hibernateTemplate实现的增删改操作。。。
}
=================================上面这样是运行正常的,后来改了代码:
BaseDao:
public class BaseDao extends HibernateDaoSupport {
public List findAll(String object) {
return this.
getHibernateTemplate().find("from " + object);
}
。。。。。。
}
ExpertDao:
@Component("expertDao")
public class ExpertDao extends BaseDao {
public List findAll() {
return super.findAll(objname);
}
}
=================================这样改了就提示错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'expertDao' defined in file [E:\Project\WebRoot\WEB-INF\classes\com\ExpertDao.class]: Invocation of init method failed;
nested exception is java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
------解决方案--------------------lz查看hibernateTemplate的源码就知道,hibernateTemplate类中有个sessionFactory类,不知道zl的问题有没有解决
------解决方案--------------------原先的代码:(运行正确)
BaseDao:
public class BaseDao {
protected HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
@Resource
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
}
ExpertDao:
@Component("expertDao")//这行什么意思?
public class ExpertDao extends BaseDao {
//用hibernateTemplate实现的增删改操作。。。
}
=================================上面这样是运行正常的,后来改了代码:
BaseDao:
public class www.8892.orgBaseDao extends HibernateDaoSupport {
public List findAll(String object) {
return this.getHibernateTemplate().find("from " + object);
}
。。。。。。
}
ExpertDao:
@Component("expertDao")
public class ExpertDao extends BaseDao {
public List findAll() {
return super.findAll(objname);
}
}
=================================这样改了就提示错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'expertDao' defined in file [E:\Project\WebRoot\WEB-INF\classes\com\ExpertDao.class]: Invocation of init method failed; nested exception is
java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
看不懂啊
------解决方案--------------------@Compo