What does the classpath path mean?
Only know the configuration files such as: Mybatis.xml, Spring-web.xml, Applicationcontext.xml and so on to the SRC directory (that is, the directory of the Code. Java files), and then use the "Classpath:xxx.xml" To read, are placed in the SRC directory quasi-correct, then exactly classpath exactly what position?
- The Web-inf/classes directory holds the. class file, XML, properties, and other resource profiles that are compiled by the SRC directory Java file, which is an entry point for locating resources .
- The files under the SRC path are compiled and placed under the web-inf/classes path, and the default classpath is here. If you put it directly under the Web-inf, it is not under the classpath. With the Classpathxmlapplicationcontext, of course, can't get.
ApplicationContext ctx = new ClassPathXmlApplicationContext("xxxx.xml"); //读取classPath下的spring.xml配置文件
- To refer to a file under the Classpath path, simply add classpath before the file name:
<param-value>classpath:applicationContext-*.xml</param-value> <!-- 引用其子目录下的文件,如 --><param-value>classpath:context/conf/controller.xml</param-value>
- Lib and classes belong to Classpath, and the access priority for both is: lib>classes.
The difference between classpath: and classpath*: In the web. XML configuration
Classpath: And classpath*: Difference:
- Classpath: Only find files in your class path;
- Classpath*: Includes not only the class path, but also the jar file (the class path) to find.
- If the resource to be loaded is not in the current ClassLoader path, then the classpath: prefix is not found, in which case you need to use the classpath*: prefix
- A resource with the same name exists in multiple classpath and needs to be loaded, then classpath: Only the first one is loaded, and in this case classpath*: prefix is required.
Classpath*: The use of
When there are multiple classpath paths in the project, and the files that load multiple classpath paths at the same time (most of which are not encountered in this case), * play a role, and if you do not add *, only the first classpath path is loaded, the code snippet:
<param-value>classpath*:context/conf/controller*.xml</param-value>
Other than that:
"**/" means any directory;
"**/applicationcontext-*.xml" represents an XML file that begins 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 application's web-inf/classes directory like the class file
Attention:
With classpath*: Need to traverse all the classpath, so the loading speed is very slow, therefore, in planning, should be as far as possible to plan the path of the resource files, try to avoid the use of classpath*
What path does classpath specifically refer to in a Java Web project?