我在 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:
,搜索起来是否更快<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:
总是相对于类路径根。如果将/
放在路径的开头,则会将其静默删除。
不,那根本行不通。 classpath根目录包含/WEB-INF/classes
,因此该路径应该是相对的。
不要将classpath:
路径与文件路径混淆,它们之间没有关系。