In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you the "springMVC web.xml configuration loading order is how", the content is easy to understand, clear, hope to help you solve doubts, the following let Xiaobian lead you to study and learn "springMVC web.xml configuration loading order is what kind of" this article.
Configuration loading order in springMVC web.xml
Let's not elaborate on the specific configuration in the web.xml file here, but simply explain the loading order of the configuration information in it:
The order in which elements are loaded in the web.xml file is independent of their order in the web.xml file.
The loading order is context-param- > listener-> filter-> servlet, where context-param, which is used to provide ServletContext with key-value pairs, that is, application context information. Our listener, filter, etc., use the information in this context during initialization, but for some configuration sections, the order in which they appear is related.
Here is a supplement to the following problems encountered in the configuration and how to solve them:
There are generally two configuration files for spring defined in web.xml
1. Configuration file for Spring context
ApplicationContext.xml
ContextConfigLocation classpath:applicationContext.xml 2, SpringMVC configuration file
Spring-servlet.xml
The loading order of spring org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:spring-servlet.xml 1 is
The Spring context configuration file is loaded first, then the SpringMVC configuration file is loaded, and if the same content is configured, the SpringMVC configuration file takes precedence. So one thing to pay attention to here is that the contents of the SpringMVC configuration file do not overwrite the contents of the Spring context configuration file.
For example, the service layer is first introduced into the Spring context configuration file, and then transactions are added:
However, all classes (including the service layer, of course) are introduced by default in the SpringMVC configuration file, but no transactions are added
Then the transaction function doesn't work at this point, that is, adding the @ Transactional annotation to the code is invalid. So to prevent this problem, it is common to introduce all the classes in the Spring context configuration file and add transactions:
Only the controller layer is introduced in the SpringMVC configuration file:
Web.xml loading sequence and Spring package scanning Note 1. Loading sequence of configuration files in web.xml files
In the web.xml file, we usually configure some configuration files that need to be loaded when the project starts. For example, during the development of SpringMVC project
We usually have two xml configuration files. One context configuration file applicationContext.xml, and the other is the springMVC configuration file servlet-context.xml file.
Loading order:
1. When the server starts, it will first look for the web.xml file and load the configuration file in the web.xml file
two。 After finding the web.xml, load the context configuration file first; that is, the initialization file in the tag. It can use wildcards to specify the path to load multiple files; for example: application*.xml.
3. Load the listener;.
4. Load the filter;.
5. Load Servlet;. For example, SpringMVC's configuration file servlet-context.xml.
2. When SpringMVC configures transaction management
Configuration considerations when scanning @ Service,@Controller package files:
1. When we add the transaction configuration of Spring in applicationContext.xml and the scan @ service package path in servlet-context.xml
When we add transaction annotations to the method in Service, we find that the transaction does not work. When you put it in the same xml configuration file as the transaction configuration, it's fine. In general, the Service layer is scanned before the Controller layer.
two。 Spring transactions also do not work when the path to scan the Service package is added to the applicationContext.xml file, and the scan is added to the servlet-context.xml file at the same time. Because the configuration in the configuration file in SpringMVC will overwrite the content in applicationContext.xml.
The above is all the content of the article "what is the loading order of configuration in springMVC web.xml". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.