在使用Mybatis时,出现Could not find resource WEB-INF/config/mapper.xml的错误,明显知道是文件路径写的不对,但无论怎么改正,都是这个错误。我的mapper.xml文件错误的放在如下位置:

Could not find resource WEB-INF/config/mapper.xml

 我的配置文件如下所示:

Could not find resource WEB-INF/config/mapper.xml 

经过查找资料发现<mapper resource="" />默认会在类路径下查找文件,但我的mapper.xml文件并不在类路径下

但src/main/resouces目录中的文件会被复制到target/classes(即类路径)目录中。所以有了解决办法

解决方法

在src/main/下新建resources文件并把mapper.xml放到该文件中。如下所示:

Could not find resource WEB-INF/config/mapper.xml

然后发现类路径下出现了mapper.xml文件 

Could not find resource WEB-INF/config/mapper.xml 

 最后配置文件中如下表示mapper.xml的路径

Could not find resource WEB-INF/config/mapper.xml 

问题得到解决。 

相关文章:

  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-05-07
猜你喜欢
  • 2021-08-15
  • 2021-11-03
  • 2021-11-28
  • 2022-12-23
  • 2021-08-26
  • 2021-07-20
  • 2022-12-23
相关资源
相似解决方案