搭建新的springboot项目,在集成了mybatis之后,代码写完启动项目报错:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.kd.csc.imbar.mapper.KDproductMapper.getAllProd
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:227)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:49)
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:65)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:58)
at com.sun.proxy.$Proxy93.getAllProd(Unknown Source)
at
根据报错分析,可得知是所写的mapper文件在启动时没有注入,但是在代码编写的时候已经引用了@mapper的注解,也不需要mapperScan注解,就觉得很诡异。
@Mapper
public interface FastEnterMapper
在mapper.xml文件中配置的namespace文件指向和参数类型也都是正确的
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kd.csc.imbar.mapper.FastEnterMapper">
</mapper>
那么接下来要分析的就是在搭建项目的过程中是不是会出现配置错误的问题:
1、检查pom文件中的mybatis配置是不是配置了多份,或者配置错误,jdbc、mybatis、mysql配置如下
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
2、检查properties配置文件中的mybatis配置是不是与pom文件中的对应,配置如下
mybatis-plus.configLocations= classpath:mybatis-config.xml
mybatis-plus.mapper-locations=classpath:mapper/*.xml
我出现这个错误是因为pom中引用的是mybatis-plus,但是我最初的配置文件写成了mybatis,
修改之后重启,运行成功。😄