Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java IOException:找不到spring xml_Java_Spring_Netbeans_Exception Handling - Fatal编程技术网

Java IOException:找不到spring xml

Java IOException:找不到spring xml,java,spring,netbeans,exception-handling,Java,Spring,Netbeans,Exception Handling,我刚接触Spring并编写了我的第一个代码。运行代码时出现以下错误: Feb 09, 2014 1:21:23 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@64964f8e: startup date [Sun F

我刚接触Spring并编写了我的第一个代码。运行代码时出现以下错误:

Feb 09, 2014 1:21:23 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@64964f8e: startup date [Sun Feb 09 13:21:23 IST 2014]; root of context hierarchy
Feb 09, 2014 1:21:23 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not exist
我尝试了几种组合,将spring.xml移动到不同的位置,发现了相同的问题。 以下是我的文件夹结构:

尝试将SpringXML复制到您的com文件夹。它正在您当前的文件夹中搜索它。如果要将其存储在其他文件夹中,则它应位于类路径上,并且在使用ClasspathXmlApplicationContext加载此文件时,应使用项目根目录中的路径。如果resources文件夹不在类路径中,则在您的示例中使用示例:/resources/spring.xml

  • 确保resources文件夹位于classpth中
  • spring.xml
    名称更改为
    /spring.xml
    。在路径之前需要斜杠。您应该将路径配置为绝对路径,而不是相对路径

  • 您确定资源在我们的类路径中吗?它不是maven项目,所以资源可能不是类路径根目录。最简单的方法是内部调试spring代码。在本例中,您将能够了解有关spring的更多信息。如何将资源添加到classpath下面的链接stackoverflow.com/questions/7598623/…,我将classpath添加到了resources,但仍然无法工作。上面的ss是我尝试过的最新代码,将spring.xml复制到com文件夹,并将路径更改为resource/spring.xml。仍然是相同的errpr。如果spring.XML在com文件夹中,那么不需要指定/resources/spring.XML.no,实际上当它在资源文件夹中时,我提到了wirh/resource/spring.XML。。没用。然后我把它放在com文件夹中,名为spring.xml。。。仍然不起作用您有2个选择1)复制到com文件夹并在类中指定spring.xml 2)将其放在resources文件夹中并在类中指定/resources/spring.xml您可以共享项目的最新代码和类路径吗