The difference between classpath: and classpath*: in web.xml configuration

classpath refers to the classes directory under the WEB-INF folder.
The role of classes: 
1. Store various resource configuration files eg.init.properties log4j.properties struts.xml 
2. Store template files eg.actionerror.ftl 
3. Store class files corresponding to the src directory compilation files during project development 
4. This involves the problem of file access priority under lib and classes: The 


difference between lib>classes classpath and classpath*: 
classpath: only look for files in your class path; 
classpath*: not only includes class path, but also jar files in (class path) to search. 

Java code 
  1. <param-value>classpath:applicationContext-*.xml</param-value>  

Or refer to files in its subdirectories, such as 

Java code  
  1. <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  
  1. <param-value>classpath*:context/conf/controller*.xml</param-value>  


In addition: 
"**/" means any directory; 
"**/applicationContext-*.xml" means any 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. , which will be loaded from all classpaths. If the resource to be loaded is not in the path of the current ClassLoader, it cannot be found with the classpath: prefix. In this case, you need to use the classpath*: prefix. If there are resources with the same name in multiple classpaths, all of them 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: 
When 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*.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326393657&siteId=291194637