SM报错Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

2019/4/3

问题描述
在练习SM框架时,当我写好了所有必要的代码和配置文件并运行是,报如下错:

Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

解决思路
根据错误信息可以知道,我在Spring容器中配置Dao层实现类的bean相关属性时,漏掉了sqlSessionFactory或者sqlSessionTemplate这两个属性。虽然这个实现类里面我并没有写这两个属性,但是这个实现类实现了SqlSessionDaoSupport的继承,在SqlSessionDaoSupport中是有sqlSessionFactory属性的,所以需要在Spring容器中配置Dao层实现类的bean中配置sqlSessionFactory,将sqlSessionFactory交给Dao层。

解决方法

	<bean id="studentMapper" class="dao.Impl.StudentDaoImpl">
		<!-- 将Spring配置的sqlSessionFactory交给dao -->
		<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
	</bean>

猜你喜欢

转载自blog.csdn.net/qq_42323185/article/details/88989537