前言:本人在将不适用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>
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>
错误消失。