【使用Maven搭建的项目,报错:Invalid bound statement (not found): com.company.mapper.TbItemMapper.selectByPrimaryKey】

转自:http://blog.csdn.net/lxy344x/article/details/51912493

使用maven搭建的项目,运行编译没有问题,测试时在地址栏输入:http://localhost:8080/WMS/item/1,回车报错:

HTTP Status 500 - Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.company.mapper.TbItemMapper.selectByPrimaryKey

错误说的是找不到selectByPrimaryKey,查看mapper映射文件,发现方法名和接口都一一对应,没有错误,再查看编译后的文件目录:

    

发现只有class文件,没有xml文件,但是xml文件命名存在,只是没有被加载到spring容器中,所以访问不到

 

解决方法:

在当前工程的pom.xml中添加节点:

<build>
    <resources>
	<!-- 如果不添加这一句,mapper包下的*.xml映射文件将无法被加载到classes下 -->
	<resource>
		<directory>src/main/java</directory>
		<includes>
			<include>**/*.properties</include>
			<include>**/*.xml</include>
		</includes>
		<filtering>false</filtering>
	</resource>
	<!-- 2:同时也要保证src/main/resources下的文件发布到目录文件中 -->
	<resource>
		<directory>src/main/resources</directory>
		<includes>
			<include>**/*.properties</include>
			<include>**/*.xml</include>
		</includes>
		<filtering>false</filtering>
	</resource>
    </resources>
</build>

 如果不加2,将报如下错误:

 

posted @ 2017-06-20 17:26  半生戎马,共话桑麻、  阅读(306)  评论(0)    收藏  举报
levels of contents