共计 572 个字符,预计需要花费 2 分钟才能阅读完成。
- 在用 maven 配置 mybatis 环境时出现此 BindingExceptiony 异常,发现在 classes 文件下没有 mapper 配置文件,应该是 maven 项目没有扫描到 mapper 包下的 xml 文件,在 pom.xml 中加入一下代码可以解决:
 
 <build>
    <resources>
      <!-- maven 项目中 src 源代码下的 xml 等资源文件编译进 classes 文件夹,注意:如果没有这个,它会自动搜索 resources 下是否有 mapper.xml 文件,如果没有就会报 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.pet.mapper.PetMapper.selectByPrimaryKey-->
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
      <!-- 将 resources 目录下的配置文件编译进 classes 文件  -->
      <resource>
            <directory>src/main/resources</directory>
      </resource>
    </resources>
  </build>正文完
发表至: Java
 2019-08-24