ERROR 8596 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.zhang.chapter5_4.dao.UserDao.getUser] with root cause
1.检查mapper.xml中的参数类型以及ID和Dao接口中的是否一致;这里没问题
2.看是否有配置Mybatis映射文件路径:mybatis.mapper-locations,这里没问题
3.检查target下是否有mapper.xml文件,出问题了没有该类文件
- 如果你把mapper.xml放到了resources文件下,那么就只需要配置mybatis.mapper-locations=classpath:/mapper/.xml 就可以了,因为构建的时候会把resources里的东西自动拉到classpath下
- 当mapper.xml文件在src/main/java下时,IDEA编译时默认不会该类型文件编译进target
解决方法:
在该项目的pom.xml文件中的<build>
标签中添加,然后项目上右键选择maven
->reload project
,成功解决问题
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>