为啥 FileSystemXmlApplicationContext 在存在的文件上抛出 FileNotFoundException

Posted

技术标签:

【中文标题】为啥 FileSystemXmlApplicationContext 在存在的文件上抛出 FileNotFoundException【英文标题】:Why FileSystemXmlApplicationContext throws FileNotFoundException on file that exists为什么 FileSystemXmlApplicationContext 在存在的文件上抛出 FileNotFoundException 【发布时间】:2012-06-18 13:36:19 【问题描述】:

我正在运行以下代码:

new FileSystemXmlApplicationContext("/data/farm/Server/confData/1000004/contex.xml")

它会抛出

java.io.FileNotFoundException: class path resource [data/farm/Server/confData/1000004/contex.xml] cannot be opened because it does not exist

文件存在,我可以做

cat /data/farm/Server/confData/1000004/contex.xml

并查看其内容。 同样在 Windows 中,此代码正在运行 - 问题出在 linus 中(我有 ubuntu os)

谁能告诉我这里出了什么问题?

【问题讨论】:

看看这个forum.springsource.org/… 【参考方案1】:

尝试使用 Url 创建 FileSystemXmlApplicationContext,例如:

new FileSystemXmlApplicationContext("file:/data/farm/Server/confData/1000004/contex.xml");

更多解释见:http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch05s07.html 5.7.3 FileSystemResource 警告

【讨论】:

谢谢,就是这个。 :-) 我也试过这样做,当我从 IDE 运行代码时它可以工作,但是当我编译 jar 文件并尝试执行它时它不起作用,得到 fileNotFoundException。任何想法,出了什么问题?谢谢 也许是因为这个? ***.com/questions/14483160/… @IstvanDevai 这个帖子的答案是一样的,使用“file:”作为前缀......这就是我所做的

以上是关于为啥 FileSystemXmlApplicationContext 在存在的文件上抛出 FileNotFoundException的主要内容,如果未能解决你的问题,请参考以下文章

为啥 DataGridView 上的 DoubleBuffered 属性默认为 false,为啥它受到保护?

为啥需要softmax函数?为啥不简单归一化?

为啥 g++ 需要 libstdc++.a?为啥不是默认值?

为啥或为啥不在 C++ 中使用 memset? [关闭]

为啥临时变量需要更改数组元素以及为啥需要在最后取消设置?

为啥 CAP 定理中的 RDBMS 分区不能容忍,为啥它可用?