spring配置文件中配置sessionFactory失败

配置失败主要原因有两个:

<bean id="studentDaoImp" class="com.gxwuz.maven.dao.StudentDaoImp">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

一是dao层的类没有写private SessionFactory sessionFactory;   和setSessionFactory方法(如上面的SudentDaoImp要写这些)

二是spring的配置文件中配置sessionFactory时没配置好,如hibernate.cfg.xml文件路径配置错误而且必须配置dataSource,configLocation,mappingLocations如下图:

当然configLocation也可以直接配置,如下图:

当然mappingLocations也可以用另一种写法;

原文地址:https://www.cnblogs.com/chuangqi/p/10500616.html