首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring无法加载xml配置文件

Spring无法加载xml配置文件
EN

Stack Overflow用户
提问于 2015-09-15 19:11:15
回答 2查看 1.2K关注 0票数 0

这个错误打击了我的大脑。所有的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等中的资源文件,而只加载类。

EN

回答 2

Stack Overflow用户

发布于 2015-09-15 19:25:42

您得到的FileNotFoundException确实指出,beans.xml文件不在您认为的位置的jar中。我想看看那个罐子里的东西。例如,您可以打开jar 使用7-zip工具。我发现,这提供了有用的洞察力,当你得到类似于你报告的错误。

票数 1
EN

Stack Overflow用户

发布于 2015-09-15 19:27:20

如果您要获得FileNotFoundException,这是因为文件不在您要查找的位置。beans.xml文件必须位于src/main/resources

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32593801

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档