Spring MVC churn configuration file path

Source: Internet
Author: User

1.1. Classpath

Project folder


In the Web. xml file such as the following configuration:

<!-- Configure the core servlet of springMVC --

< servlet >

< Servlet-name >Spring</servlet-name>

< Servlet-class >org.springframework.web.servlet.DispatcherServlet</servlet-class>

< Init-param >

< Param-name >contextconfiglocation</param-name>

<!-- Specify the path to the springMVC configuration file/web-inf/<[servlet-name]-servlet.xml> like this here for/web-inf/ Spring-servlet.xml

The following configuration is also the default value--

<param-value>classpath:config/spring-servlet.xml</param-value>

</ Init-param >

<!-- The configuration starts with the server itself proactively initialized --

< Load-on-startup >1</load-on-startup>

</ servlet >

< servlet-mapping >

< Servlet-name >Spring</servlet-name>

<!-- filter all suffixes named. Do requests--

< Url-pattern >*.do</url-pattern>

</ servlet-mapping >

1.2. classpath*

The project folder is the same as above

The Web. xml file is configured for example:

<!-- Configure the core servlet of springMVC --

< servlet >

< Servlet-name >Spring</servlet-name>

< Servlet-class >org.springframework.web.servlet.DispatcherServlet</servlet-class>

< Init-param >

< Param-name >contextconfiglocation</param-name>

<!-- Specify the path to the springMVC configuration file/web-inf/<[servlet-name]-servlet.xml> like this here for/web-inf/ Spring-servlet.xml

The following configuration is also the default value--

<param-value>classpath*:config/spring-servlet.xml</param-value>

</ Init-param >

<!-- The configuration starts with the server itself proactively initialized --

< Load-on-startup >1</load-on-startup>

</ servlet >

< servlet-mapping >

< Servlet-name >Spring</servlet-name>

<!-- filter all suffixes named. Do requests--

< Url-pattern >*.do</url-pattern>

</ servlet-mapping >

1.3. What is Classpath?

Set Classpath the purpose. is to tell the java Runtime which folders are able to find The classes or packages that you need to run the Java program .

Classpath refers to the classes folder under the Web-inf folder. When the Web app is advertised to the server, the compiled class and resource files for all of the classes under the SRC folder are placed into the Classes folder under the Web-inf folder.

1.4. The difference between classpath and classpath*

Classpath: Just look for the file in your class path.

Classpath*: Includes not only the class path. Also included in the jar file (class path) to find.

1) The former will only be loaded from the first classpath, and the latter will be loaded from all classpath.

2) Assume the resource to be loaded. Not in the current ClassLoader path, then the classpath: prefix is not found, in this case you need to use the classpath*: prefix.

3) in multiple classpath with the same name of the resource, all need to load, then use CLASSPATH: Only load the first, in this case also need to use classpath*: prefix.

4) Use classpath*: Need to traverse all classpath. So the loading speed is very slow, so when planning, you should plan the path of the resource file as well as possible. Try to avoid using classpath*.

Spring MVC churn configuration file path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.