在IJ中Mybatis加载配置文件出现错误: java.io.IOException: Could not find resource SqlMapConfig.xml

 在用IJ初学Mybatis框架时,在已经写好的程序进行运时出现以下错误:

      当我们在项目中和src同级的目录创建一个文件config时,在此文件中编写了SqlMapConfig.xml , 此时我们需要读取此配置文件来创建SqlSessionFactory 来作为一个测试类来测试,却发现报出Could not find resource SqlMapConfig.xml 的解决方法:

   首先看一下项目结构:

    在IJ中Mybatis加载配置文件出现错误: java.io.IOException: Could not find resource SqlMapConfig.xml

 程序中的加载配置文件的代码:

   在IJ中Mybatis加载配置文件出现错误: java.io.IOException: Could not find resource SqlMapConfig.xml

  

如果是这样的话的可以这样解决试试: 在建立的文件夹config 右击 , 点击  Mark  Directory as ,选择test  Resource Root ,然后重新运行结果就对了。

  在IJ中Mybatis加载配置文件出现错误: java.io.IOException: Could not find resource SqlMapConfig.xml