The difference between classpath: and classpath*: in the web.xml configuration of the Java web project

First, classpath refers to the classes directory under the WEB-INF folder.

Explain meaning of classes:
1. Store various resource configuration files eg.init.properties log4j.properties struts.xml
2. Store template files eg.actionerror.ftl
3. Store classes The file corresponds to the compiled file in the src directory during project development
Summary : This is an entry for locating

resources The problem is the access priority of files under lib and classes: the impact of lib>classes on performance should not be in this category . The difference between classpath and classpath*: classpath: only look for files in your classpath; classpath*: not only contains classes path, including the jar file (class path) for searching. <param-value>classpath:applicationContext-*.xml</param-value>  or refer to the files in its subdirectories, such as <param-value>classpath:context /conf/controller.xml</param-value> 
















Use of classpath*: When there are multiple classpath paths in the project, and files under multiple classpath paths are loaded at the same time (mostly not encountered in this case), * will play a role. If * is not added, it means that only loading The first classpath path, code snippet:
Java code collection code
<param-value>classpath*:context/conf/controller*.xml</param-value> 


In addition:
"**/" means any directory;
"* */applicationContext-*.xml" represents an XML file starting with "applicationContext-" in any directory. 
After the program is deployed to tomcat, the configuration file in the src directory will be automatically copied to the WEB-INF/classes directory of the application, the same as the class file.
The difference between classpath: and classpath*: is that the

former will only be loaded from the first classpath. , and the
latter  will load from all classpaths.

If the resource to be loaded is
not in the path of the current ClassLoader, then the classpath: prefix cannot be found.
In this case, you need to use the classpath*: prefix

on multiple classpaths If there are resources with the same name in the file, they all need to be loaded,
then using classpath: will only load the first one. In this case, you also need to use the classpath*: prefix.

Note :
Using classpath*: You need to traverse all classpaths, so the loading speed is very slow. Therefore, when planning, you should plan the path where the resource files are located as much as possible, and try to avoid using classpath*.


from : http://perfy315.iteye.com/blog/2009258

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327002778&siteId=291194637