其中"classpath *"是在Spring MVC Project中声明的? [英] Where "classpath*" is declared in Spring MVC Project?
问题描述
我对此感到很好奇.
此"classpath *"声明在哪里?
Where is this "classpath*" declaration?
通常在web.xml中描述以下内容.
Follow is normaly descripted in web.xml.
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:egovframework/springmvc/context-*.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
我认为该框架首先阅读了web.xml.但是,如何知道这个关键字"classpath *:"呢?
I thought this framwork read web.xml first. However how can it knows this keyword "classpath*:" ?
提前感谢您:D
推荐答案
I believe spring docs describe class path resources well:
ClassPathResource
此类代表一种资源,应从类路径.这将使用给定的线程上下文类加载器类加载器,或用于加载资源的给定类.
This class represents a resource which should be obtained from the classpath. This uses either the thread context class loader, a given class loader, or a given class for loading resources.
如果此资源实现支持将解析为java.io.File类路径资源位于文件系统中,但不适用于驻留在jar中且尚未扩展的classpath资源(通过servlet引擎或任何环境)文件系统.为了解决这个问题,各种资源实现始终支持将解析作为java.net.URL.
This Resource implementation supports resolution as java.io.File if the class path resource resides in the file system, but not for classpath resources which reside in a jar and have not been expanded (by the servlet engine, or whatever the environment is) to the filesystem. To address this the various Resource implementations always support resolution as a java.net.URL.
由Java代码使用以下代码显式创建ClassPathResourceClassPathResource构造函数,但通常会隐式创建当您调用带有String参数的API方法时,该参数是旨在代表一条道路.对于后一种情况,使用JavaBeansPropertyEditor将识别特殊前缀classpath:字符串路径,并在这种情况下创建ClassPathResource
A ClassPathResource is created by Java code explicitly using the ClassPathResource constructor, but will often be created implicitly when you call an API method which takes a String argument which is meant to represent a path. For the latter case, a JavaBeans PropertyEditor will recognize the special prefix classpath:on the string path, and create a ClassPathResource in that case
这篇关于其中"classpath *"是在Spring MVC Project中声明的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!