这个错误打击了我的大脑。所有的junit测试都很好,但是当我的应用程序作为另一个应用程序的插件加载时,我会有一个错误。beans.xml在jar文件的根目录下是100%,但由于某些原因,加载插件的主应用程序找不到该文件。为什么?
在我的应用程序的引导方法中,我调用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等中的资源文件,而只加载类。
发布于 2015-09-15 19:25:42
您得到的FileNotFoundException确实指出,beans.xml文件不在您认为的位置的jar中。我想看看那个罐子里的东西。例如,您可以打开jar 使用7-zip工具。我发现,这提供了有用的洞察力,当你得到类似于你报告的错误。
发布于 2015-09-15 19:27:20
如果您要获得FileNotFoundException,这是因为文件不在您要查找的位置。beans.xml文件必须位于src/main/resources中
https://stackoverflow.com/questions/32593801
复制相似问题