出现这种情况有两种。
一、使用Maven进行打包的时候,没有将XXXMapper.xml这些资源文件一起打包。
这种情况,可以发现在打包文件夹target中,找不到相关的Mapper.xml文件。
解决方式:
1. Maven解决,打包的时候将资源文件一起打包。
在pom.xml
中添加如下语句,主要是resources部分(打包xml和properties文件)
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
- idea。放置在resources文件夹下,或者将所在资源文件夹手动设置为资源文件。
二、配置springmvc出错
在配置Spring-mybatis的时候有错误。尝试一下配置
<!-- 让spring管理sqlsessionfactory 使用mybatis和spring整合包中的 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据库连接池 -->
<property name="dataSource" ref="dataSource" />
<!-- 加载mybatis的全局配置文件 -->
<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml" />
<!-- mapper文件位置 -->
<property name="mapperLocations" value="classpath:mapping/*Mapper.xml"/>
</bean>