Could not find resource com/cth/dao/UserImpl.xml 单映射文件找不到

报错:

### The error may exist in com/cth/dao/UserImpl.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/cth/dao/UserImpl.xml
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	at com.cth.domain.User.main(User.java:17)
	……

原因

因为com/cth/dao/下的UserImpl.xml文件没有被编译到target/classes目录下对应的目录中,不信你可以在项目中的target/classes目录下找一找,绝对是找不到的

解决方法:

  1. 方法一:com/cth/dao目录下的文件放到resource目录下

  2. 方法二:在pom文件中添加以下代码

    <build>
        <resources>
          <resource>
            <directory>src/main/java</directory>
            <includes>
              <include>**/*.properties</include>
              <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
          </resource>
        </resources>
      </build>
    
上一篇:Mybatis-Plus控制台打印日志


下一篇:SpringBoot整合MyBatis时报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not foun