Spring contextconfiglocation The location of the default load file

Source: Internet
Author: User

When using the spring framework, if we are using an XML file configuration bean, we tend to configure the following in Web. xml:

    <Context-param>        <Param-name>Contextconfiglocation</Param-name>        <Param-value>/web-inf/config/spring-bean-config.xml</Param-value>    </Context-param>        <Listener>        <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>    </Listener>

This is because if we have configuration Contextloaderlistener, spring will go to the Web. XML to see if we have defined contextconfiglocation This parameter, if there is a spring container (bean Factory) The bean that is defined in the XML file is loaded into the container, what will spring do if the contextconfiglocation parameter is not defined? Will the Web server start with an error?

Spring has a concept that the contract is better than the configuration, that is, even if you do not display the location of the definition XML file, the spring container will go to a convention place to find the file, if not found to report FileNotFoundException, let us take a look at the following code snippet:

"/web-inf/applicationcontext.xml" is the default file address, if you use spring MVC, you must go to the Web. Xml to define Dispatcherservlet

  <  servlet  >  <  servlet-name  >  dispatcherservlet</  Servlet-name  >  <  servlet-class  >  Org.springframework.web.servlet.dispatcherservlet</ servlet-class     >  </ servlet  >  

This time if you do not display the configuration contextconfiglocation parameter, spring will load the configuration file "Web-inf/dispatcherservlet-servlet.xml" under the default path, and if it does not exist, it will report an exception.

The above source code exists in Xmlwebapplicationcontext.

Spring contextconfiglocation The location of the default load file

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.