使用Spring获取WEB-INF下的文件
我正在尝试使用 Spring 在 WEB-INF/classes 文件夹下获取一个文件。
<bean id="myBean" class="path.to.MyBean" >
<property name="myFile">
<value>file:WEB-INF/classes/myFile.foo</value>
</property>
</bean>
但是,当我从 MyBean 内部打印出 myFile 的文件路径时,它是:
c:\\apache\bin\WEB-INF\classes\myFile.foo
所以它没有使用相对部署路径。
我做错了什么吗?
I am trying to get a File under my WEB-INF/classes folder using Spring.
<bean id="myBean" class="path.to.MyBean" >
<property name="myFile">
<value>file:WEB-INF/classes/myFile.foo</value>
</property>
</bean>
However, when I print out the myFile's File Path from inside MyBean it is:
c:\\apache\bin\WEB-INF\classes\myFile.foo
So it is not using the relative deployment path.
Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
或
Try:
or
使用:
并使用以下方式读取它:
myFile
是一个String
。另一种方法是将文件存储在与
MyBean
(/WEB-INF/classes/path/to/myFile.foo
)包相同的目录中并读取以下方式:请注意,没有前导
/
- 路径相对于当前类(getClass()
调用)。Use:
and read it using:
myFile
is aString
.Another approach is to store the file in the same directory as the package of
MyBean
(/WEB-INF/classes/path/to/myFile.foo
) and read it in the following way:Notice there is no leading
/
- the path is relative to the current class (getClass()
invocation).