【问题标题】:Spring 3 HelloWorld Program春季 3 HelloWorld 程序
【发布时间】:2012-05-14 17:07:17
【问题描述】:

我目前正在尝试启动并运行一个 spring 程序。我正在使用this 示例来教我如何做。我已经完成了示例中所说的所有操作,但当我尝试在第 12 步中运行它时,我得到了一个错误。

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [SpringHelloWorld.xml]; nested exception is java.io.FileNotFoundException: class path resource [SpringHelloWorld.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:78)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:66)
at net.roseindia.Spring3HelloWorldTest.main(Spring3HelloWorldTest.java:12)

原因:java.io.FileNotFoundException:类路径资源[SpringHelloWorld.xml]无法打开,因为它不存在 在 org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) 在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) ... 4 更多

我对春天真的很陌生,所以我真的不知道发生了什么。我知道在我的课堂上我尝试导入 org.springframework.beans.factory.xml.XmlBeanFactory;,但我认为这是引发错误或导致它不起作用的原因。

如果有人知道出了什么问题,或者一个更好的易于遵循的 Spring 示例,将不胜感激。

摩根

【问题讨论】:

    标签: java spring


    【解决方案1】:

    将该 XML 文件放入您的 CLASSPATH 中。 Bean Factory 找不到您的配置文件。

    您可以使用 java.exe 的 -cp 选项来执行此操作:

    java -cp .;<individual-jars>;<directory-where-xml-config-lives> Spring3HelloWorldTest
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-19
      • 2012-02-19
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 2019-04-19
      • 2018-06-26
      • 2018-06-15
      相关资源
      最近更新 更多