Preface: In fact, it is possible that the configuration file is not loaded when the server starts. However, if you operate in this way, each time you get the corresponding object, you will read the configuration file once, thereby reducing the efficiency of the program. Spring has provided us with a listener to listen to whether the server is started, and then at startup, the configuration file of spring is loaded and only loaded once, thereby improving program efficiency.
Implementation: Its configuration needs to be performed in web.xml, the specific implementation is as follows:
<!--Configure the listener--> <!--To load the spring configuration file when the server starts--> <listener> <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/spring-context.xml</param-value> </context-param>
Note: Here, please note that the content in <param-name> in the <context-param> tag is a fixed value, and the content in <param-value> is a fixed format: classpath:spring configuration file (please add it if there is a path)
Through the above configuration, the spring configuration file can be loaded as the server starts.
Summarize
The above is the Spring Web project spring configuration file introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!