IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist

运行 Spring 项目时出现类似下面的错误信息

 class path resource [applicationContext.xml] cannot be opened because it does not exist

翻译:没有找到你的 .xml 配置文件

原因

在Test测试类中我使用的是:

 ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

获取配置文件。

ClassPathXmlApplicationContext()方法是在其所在的目录中寻找 .xml 配置文件。

注意: 这里指的是编译后的 .class 文件所在的目录,不是 .java 文件

解决

点击 File -> Project Structure,选择Modules -> Paths -> Output Paths
修改为 applicationContext.xml 文件所在目录。

相关文章:

  • 2021-11-04
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
  • 2021-06-14
  • 2022-12-23
  • 2021-08-06
猜你喜欢
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2021-09-04
  • 2021-10-20
  • 2021-06-27
  • 2021-10-19
相关资源
相似解决方案