本文介绍了在春季使用classpath:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于春季的classpath:选项,我有两个问题:-

I have two questions regarding classpath: option in spring :-

1)classpath:是否在相对于指定文档的资源中进行搜索(对于Web应用程序)?

1) Does classpath: search for resource relative to the document in which it is specified(in case of web applications)?

假设我使用以下内容:

<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>

/WEB-INF/classes/config/myconfig.xml 下的 myconfig.xml 中的

.然后从哪里开始搜索?

in myconfig.xml under /WEB-INF/classes/config/myconfig.xml. Then from where it will start its search?

2)如果我直接给出资源的位置而不是给出classpath:

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>

代替

<bean class="mybean">
<property name="myresource" value="classpath:myfile.txt"/>
</bean>

谢谢...

推荐答案

否,classpath:始终相对于类路径根.如果将/放在路径的开头,则会将其静默删除.

No, classpath: is always relative to the classpath root. If you put a / at the start of the path, it is silently removed.

不,那根本行不通.类路径根目录包含/WEB-INF/classes,因此该路径应相对于该路径.

No, that won't work at all. The classpath root contains /WEB-INF/classes, so the path should be relative to that.

不要将classpath:路径与文件路径混淆,它们之间没有关系.

Don't confuse classpath: paths with file paths, they have no relation to each other.

这篇关于在春季使用classpath:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 21:04