【发布时间】:2015-12-12 03:59:53
【问题描述】:
这个错误让我大吃一惊。所有的 junit 测试都很好,但是当我的应用程序作为另一个应用程序的插件加载时,我遇到了错误。 beans.xml 100% 位于 jar 文件的根目录,但由于某种原因,加载我的插件的主应用程序找不到该文件。为什么?
在我的应用程序的启动方法中,我调用
new ClassPathXmlApplicationContext("beans.xml");抛出
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
或
new FileSystemXmlApplicationContext(getClass().getClassLoader().getResource("beans.xml").getPath()); 抛出
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/C:/path/to/my.jar!/beans.xml]; nested exception is java.io.FileNotFoundException: C:\path\to\my.jar!\beans.xml (The system cannot find the path specified)
UPD:问题是应用程序使用了自定义类加载器,它不会在根目录、META-INF 等中加载资源文件,而只加载类
【问题讨论】:
-
“jar 文件的根目录”是什么意思,你能检查一下它所在的路径吗?
-
@Jama 我的意思是 beans.xml 必须位于 jar 文件中。
标签: java xml spring spring-mvc