IOException:找不到spring-xml

时间:2014-02-09 08:00:36

标签: 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 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移动到不同位置的几种组合,我发现了同样的问题。 这是我的文件夹结构的ss: enter image description here

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

  1. 确保资源文件夹在您的classpth中。
  2. spring.xml名称更改为/spring.xml。根据{{​​3}} this example 在路径前需要斜杠。您应该将路径配置为绝对路径,而不是相对路径。