使用类路径:在春季
我有两个关于 Spring 中的 classpath:
选项的问题:-
1) classpath:
是否相对于指定的文档搜索资源(如果是 Web 应用程序) ?
假设我使用以下内容:
<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>
在 /WEB-INF/classes/config/myconfig.xml 下的 myconfig.xml 中。那么它会从哪里开始搜索呢?
2)如果我直接提供资源位置而不是提供 classpath:
ie
<bean class="mybean">
<property name="myresource" value="classpath:/WEB-INF/classes/myfolder/myfile.txt"/>
</bean>
而不是
<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>
谢谢...,搜索是否会更快?
I have two questions regarding classpath:
option in spring :-
1) Does classpath:
search for resource relative to the document in which it is specified(in case of web applications)?
Suppose I use the following:
<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>
in myconfig.xml under /WEB-INF/classes/config/myconfig.xml. Then from where it will start its search?
2)Is it faster to search if I give direct location of the resource instead of giving classpath:
i.e
<bean class="mybean">
<property name="myresource" value="classpath:/WEB-INF/classes/myfolder/myfile.txt"/>
</bean>
instead of
<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,
classpath:
始终相对于类路径根。如果您将/
放在路径的开头,它将被静默删除。不,那根本不起作用。类路径根目录包含
/WEB-INF/classes
,因此该路径应该是相对于该路径的。不要将
classpath:
路径与文件路径混淆,它们彼此没有关系。No,
classpath:
is always relative to the classpath root. If you put a/
at the start of the path, it is silently removed.No, that won't work at all. The classpath root contains
/WEB-INF/classes
, so the path should be relative to that.Don't confuse
classpath:
paths with file paths, they have no relation to each other.看看 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-classpath-wildcards
所以
classpath:
从类路径的根开始。Take a look at http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/resources.html#resources-classpath-wildcards
So
classpath:
starts at the root of your classpath.