Spring Web project spring configuration files are automatically loaded when the server is started. spring configuration files

Source: Internet
Author: User

Spring Web project spring configuration files are automatically loaded when the server is started. spring configuration files

In fact, the configuration file does not load when the server is started. However, in this way, the configuration file will be read every time the corresponding object is obtained, thus reducing the program efficiency, spring provides a listener for us to monitor whether the server is started, and then load the spring configuration file only once at startup to improve program efficiency.

Implementation: The configuration must be performed in web. xml. The specific implementation is as follows:

<! -- Configure the listener --> <! -- Load the spring configuration file --> <listener-class> org. springframework. web. context. contextLoaderListener </listener-class> </listener> <! -- Configure the spring configuration file --> <context-param> <param-name> contextConfigLocation </param-name> <param-value> classpath: spring and spring-context.xml </param-value> </context-param>

Note: The content in the <context-param> label <param-name> is a fixed value, and the content in <param-value> is in a fixed format: classpath: spring configuration file (add a path if any)

With the above configuration, you can load the spring configuration file as the server starts.

Summary

The above section describes the Spring Web project spring configuration file automatically loaded when the server starts. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

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.