我有两个关于 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>
谢谢...
最佳答案
Does
classpath:
search for resource relative to the document in which it is specified(in case of web applications)?
不,classpath:
总是相对于类路径根。如果您将 /
放在路径的开头,它会被静默删除。
Is it more fast to search if i give direct location of resource instead e.g.
classpath:/WEB-INF/classes/myfolder/myfile.txt
不,这根本行不通。类路径根目录包含 /WEB-INF/classes
,所以路径应该是相对的。
不要将 classpath:
路径与文件路径混淆,它们之间没有任何关系。
关于spring - 使用类路径 : in spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9092713/