Java XML不存在时,它不存在
我对Intellij的想法还不熟悉,并尝试学习一些教程。我试图将XML加载到Java XML不存在时,它不存在,java,spring,intellij-idea,Java,Spring,Intellij Idea,我对Intellij的想法还不熟悉,并尝试学习一些教程。我试图将XML加载到新的ClassPathXmlApplicationContext()“中。但是,有一个错误指出FileNotFoundException Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path re
新的ClassPathXmlApplicationContext()“
中。但是,有一个错误指出FileNotFoundException
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from class path resource [vehicle_beans.xml]; nested exception is java.io.FileNotFoundException:
class path resource [vehicle_beans.xml] cannot be opened because it does not exist
这是我的结构:
这是我的密码:
这里的XML文件位置是个问题。在项目中使用Maven时,在java级别创建另一个名为“resources”的文件夹,并将XML文件放入其中
src/main/resources
Resources文件夹应包含所有与配置相关的文件,以便应用程序可以使用这些文件。否则,您必须将完整的文件路径传递给文件读取器 请尝试此FileSystemXmlApplicationContext而不是ClassPathXmlApplicationContext 专用静态最终应用程序上下文ac= 新文件系统XmlApplicationContext( “src/main/java/org/example/vehicle\u beans.xml” ); 希望它对您有用以供将来参考。