Springboot整合mybaits出现Invalid bound statement
最近在学习springcloud记录一下自己挖的坑。由于springcloud基于springboot,然后就去整合springboot和mybatis,运行项目出现
Description:
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
但是已经在application.properties配置了datasource了,然后就去target目录下查找配置文件,发现并配置文件并没有部署到target/classes文件下。后来经过排查是文件名写错了resources写成了resouces。然后执行maven clean install配置文件正常部署并运行项目,访问url出现以下提示。
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.demo.mapper.ItemDoMapper.selectByPrimaryKey
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235) ~[mybatis-3.5.4.jar:3.5.4]
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53) ~[mybatis-3.5.4.jar:3.5.4]
at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:107) ~[mybatis-3.5.4.jar:3.5.4]
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source) ~[na:1.8.0_241]
at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:94) ~[mybatis-3.5.4.jar:3.5.4]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) ~[mybatis-3.5.4.jar:3.5.4]
at com.sun.proxy.$Proxy94.selectByPrimaryKey(Unknown Source) ~[na:na]
at com.demo.service.ItemServiceImpl.selectByPrimaryKey(ItemServiceImpl.java:58) ~[classes/:na]
at com.demo.controller.ItemController.publ(ItemController.java:36) ~[classes/:na]
不对啊配置文件是正常部署的啊,为什么会访问不了mapper.xml文件呢,百度了很久给出的解决方法以下
- 接口中方法名与xml文件中 id是否一致
- xml文件中的 namespace=“xxx.xxx.xxx.Mapper” 中的路径是否与接口文件路径一致
- parameterType类型 与 resultType类型是否准确;resultMap与resultType是不一样的
- 如果上述都没问题,检查编译后的目录中是否存在mapper文件,如果没有则在对应模块的pom中加如下依赖,告诉SpringBoot不要去忽略xml文件
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>xxx/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
根据以上的方案检查完还是报错,然后就去检查一下application.properties文件,发现classpath多了一个(=)等号
一直混在绿色里面没注意到,删除 = 后项目正常运行。
自己给自己挖坑,特此记录一下