首页 > 解决方案 > 在 Spring 中添加了所有依赖项,并且 spring 配置也完成了,然后在运行时它给出了 filenotfoundexception

问题描述

File f = new File("Beans.xml");
    System.out.println("Exist test: " + f.exists());


      ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

我的项目结构:

在此处输入图像描述

标签: spring

解决方案


尝试以下解决方案 -

1.解决方案1:

尝试使用:new ClassPathXmlApplicationContext("classpath:beans.xml");

2.解决方案2:

尝试将 Bean.xml 文件移动到src/main/resources folder

并像这样访问它 -new ClassPathXmlApplicationContext("Beans.xml");

3.解决方案3:

在 spring-servlet.xml 中输入 -
<import resource="classpath*:Beans.xml" />


推荐阅读