可能造成的错误
1.两次定义了mapper的路径导致的报错
在mybatis_config.xml及applicationContext.xml同时定义了mapper
解决:删除一个(选mybatis_config.xml)
2.applicationContext.xml中的sqlSessionFactory 写错了
错误写法:
正确:
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" value="druidDataSource"/>
<property name="mapperLocations" value="classpath:mappers/UserMapper.xml"/>
<property name="typeAliasesPackage" value="com.qfedu.pojo"/>
<property name="configLocation" value="mybatis_config.xml"/>
</bean>
3.可能包的位置放错了,也可能出现上述问题