Spring Web Project Spring configuration file loads automatically with server startup

Source: Internet
Author: User

In fact, the configuration file is not loaded with the server startup is also possible, but this operation, each time you get the corresponding object, will go to read the configuration file, thereby reducing the efficiency of the program, and Spring has provided us with a listener to listen to the server is started, and then at startup, Load the spring configuration file and load it only once, improving program efficiency.

Implementation: Its configuration needs to be carried out in Web. XML, specifically implemented as follows:

 <!--Configuring Listeners - <!--to load the spring configuration file when the server starts -    <Listener>        <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>    </Listener>    <!--Configuring the Spring configuration file -    <Context-param>        <Param-name>Contextconfiglocation</Param-name>        <Param-value>Classpath:spring/spring-context.xml</Param-value>    </Context-param>

Note: Note here that the contents of <param-name> in the <context-param> tag are fixed-value,<param-value> in fixed format: classpath: Spring configuration file (if you have a path, add it)

The above configuration allows the spring configuration file to be loaded with the server startup.

by Shawn Chen 2018.1.10 Night

Spring Web Project Spring configuration file loads automatically with server startup

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.