mybatis invalid bound statement (not found) 当心文件确实不存在
2016-12-16 00:47
357 查看
前言:本人在将不适用maven的项目转化为maven项目后,遇到了 invalid bound statement (not found),百思不得其解,因为此前是可以运行的,而转为maven项目后,可以正常执行maven clean install 命令打包发布。但是访问具体某个controller后就会报出 invalid bound statement (not found)。
解决过程:
一、先试了确定常见的几个易错点没错(网上到处都有的):
1.mapper.xml 文件里的namespace对应这mapper.java 的class类型名
<?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.surpass.logistics.car.dao.CarTypeMapper" >
<resultMap id="BaseResultMap" type="com.surpass.logistics.car.domain.CarType" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat Apr 09 11:06:46 CST 2016.
-->
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="car_type" property="carType" jdbcType="VARCHAR" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_on" property="createdOn" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_on" property="updatedOn" jdbcType="TIMESTAMP" />
</resultMap>
2.自己引入的类型必须要对(点了可以跳转过去)
<resultMap id="BaseResultMap" type="com.surpass.logistics.car.domain.CarType" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat Apr 09 11:06:46 CST 2016.
-->
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="car_type" property="carType" jdbcType="VARCHAR" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_on" property="createdOn" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_on" property="updatedOn" jdbcType="TIMESTAMP" />
</resultMap>二、穷途末路,猜想引用路径的文件是否确实不存在(格外注意各种工具的打包特色)
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" />
<property name="mapperLocations" value="classpath:com/surpass/logistics/**/dao/*.xml" />
</bean>于是到class文件夹下寻找
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
发现资源文件的目录不包含src//main/java
于是改为
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>错误消失。
解决过程:
一、先试了确定常见的几个易错点没错(网上到处都有的):
1.mapper.xml 文件里的namespace对应这mapper.java 的class类型名
<?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.surpass.logistics.car.dao.CarTypeMapper" >
<resultMap id="BaseResultMap" type="com.surpass.logistics.car.domain.CarType" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat Apr 09 11:06:46 CST 2016.
-->
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="car_type" property="carType" jdbcType="VARCHAR" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_on" property="createdOn" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_on" property="updatedOn" jdbcType="TIMESTAMP" />
</resultMap>
package com.surpass.logistics.car.dao; import java.util.List; import org.apache.ibatis.annotations.Param; import com.surpass.logistics.car.domain.CarType; import com.surpass.logistics.car.domain.CarTypeExample; public interface CarTypeMapper { .... }
2.自己引入的类型必须要对(点了可以跳转过去)
<resultMap id="BaseResultMap" type="com.surpass.logistics.car.domain.CarType" >
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat Apr 09 11:06:46 CST 2016.
-->
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="car_type" property="carType" jdbcType="VARCHAR" />
<result column="created_by" property="createdBy" jdbcType="VARCHAR" />
<result column="created_on" property="createdOn" jdbcType="TIMESTAMP" />
<result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
<result column="updated_on" property="updatedOn" jdbcType="TIMESTAMP" />
</resultMap>二、穷途末路,猜想引用路径的文件是否确实不存在(格外注意各种工具的打包特色)
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/sqlMapConfig.xml" />
<property name="mapperLocations" value="classpath:com/surpass/logistics/**/dao/*.xml" />
</bean>于是到class文件夹下寻找
com/surpass/logistics/car/dao/CarTypeMapper.xml发现src/main中的所有资源文件都没有被打包进来,查找相关资料发现maven是根据以下片段来打包资源的
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
发现资源文件的目录不包含src//main/java
于是改为
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>错误消失。
相关文章推荐
- Mybatis——Invalid bound statement (not found)-Could not find result map java.lang.Integer
- springboot 集成mybatis Invalid bound statement (not found)异常
- MyBatis Invalid bound statement (not found)错误
- springmvc+mybatis 诡异问题 Invalid bound statement (not found)
- mybatis Invalid bound statement (not found)
- springboot 集成mybatis Invalid bound statement (not found)异常
- 惨痛的教训总结:SSM整合中包Mpper映射文件不存在Invalid bound statement
- Mybatis Invalid bound statement (not found)问题分析
- spring boot mybatis Invalid bound statement (not found)
- Maven项目mybatis Invalid bound statement (not found)解决方法
- Invalid bound statement (not found)-Mybatis在idea中错误
- mybatis invalid bound statement (not found) : com.XXXX
- maven + mybatis Invalid bound statement (not found) 错误解决
- Maven项目mybatis Invalid bound statement (not found)解决方法
- MyBatis Invalid bound statement
- Invalid bound statement (not found)
- invalid bound statement (not found)
- invalid bound statement (not found),大概应该是报mapper.xml中的sql查询和mapper.java中的方法没有绑定成功!
- mybatis一个怪异的问题: Invalid bound statement not found":
- Invalid bound statement (not found)