这个错误使我的大脑受到了打击。所有的junit测试都很好,但是当我的应用程序加载为另一个应用程序的插件时,我有一个错误。 beans.xml在jar文件的根目录下为100%,但由于某种原因,加载我的插件的主应用程序找不到该文件。为什么?Spring无法加载xml配置文件
在我的应用程序的启动方法,我称之为 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:问题是应用程序使用定制ClassLoader并不在根加载资源文件,META-INF等,但只有类
你是什么意思的'jar文件的根',你可以检查它位于什么路径? –
@Jama我的意思是位于jar文件中的beans.xml,因为它必须是。 – TeroBlaZe