异常org.apache.ibatibinding.BindingException: Invalid bound statement (not found): com.sxt.mybatis.map
2019-06-04 18:11
555 查看
在整合Spring Boot+MyBatis的时候出现了如下错误:
因为之前在使用SSM整合Mybatis的时候,如果把Mapper接口和Mapper.xml文件放在同一个目录下,这样就无需再做额外的配置了,可以直接使用,但是在Spring Boot中有一点点区别。
出现了以上错误,错误显示无效的绑定,找不到XML文件,首先我检查了Mapper中的方法是否和Mapper.xml中对应,然后就是Mapper文件名是否和Mapper.xml的文件名对应。通过检查,这些都是没有问题的。
然后我们可以看到,在编译的时候,target目录下根本就没有生成XML文件,所以在运行的时候就没有这个XML文件:
也可以把Mapper.xml文件放在resources下面,但是要在resources目录下创建和上面的包名一模一样的路径。因为resources实际上就是classpath,classpath就是java文件夹下面的,创建一样的目录编译的时候就会在mapper包下了:
这种情况是因为Maven中自带的过滤机制导致的,默认情况下要求把所有的XML文件,properties文件,yaml文件都放到resources目录下,因为resources才是写配置文件的地方,Java目录下是用来放Java代码的,所以在编译打包的时候,会忽略掉Java目录下的所有的配置文件,只留下Java文件。要解决这个问题只需要在pom.xml文件下指定配置文件的默认目录,在pom.xml中的build中添加如下代码即可:
<resources> <resource> <!-- 指定src/main/java为配置文件默认目录--> <directory>src/main/java</directory> <!-- 但是src/main/java目录中又不是所有的都是默认目录--> <!-- 所以还要指定**/*.xml,Java目录下的任意文件下的xml文件--> <includes> <include>**/*.xml</include> </includes> </resource> <!--此时还要使原理的配置文件目录仍然是配置配置文件目录 --> <resource> <directory>src/main/resources</directory> </resource> </resources>
相关文章推荐
- 【spring boot Mybatis】报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add
- MyBatis Error:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)(IDEA)
- mybatis多数据源错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.demo.dao.UserDa
- mybatis使用时org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):的错误
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.superr.powerful
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)新的异常解决方案
- MyBatis不能绑定xml:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- mybatis+springmvc:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- spring+mybatis整合报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- Mybatis报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)异常处理办法
- 关于mybatis的org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。
- 关于mybatis的org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- 关于mybatis “org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)” 错误的问题。
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)异常解决
- 关于mybatis的org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.png.mapper.User
- Idea+myBatis报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)