In general, in our two frameworks for integrating spring and SPRINGMVC, the Web. Xml reads:
<!--loading Spring containers-- <!--initialize the various configuration files that load Application.xml-- <context-param> <param-name>Contextconfiglocation</param-name> <param-value>Classpath:spring/applicationcontext.xml</param-value> </context-param> <listener> <listener-class>Org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!--Configuring the SPRINGMVC front-end controller- <servlet> <servlet-name>Taotao-manager</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>< Span class= "PLN" > <!--contextconfiglocation is not required, if Contextconfiglocation is not configured, SPRINGMVC configuration file by default in: Web-inf/servlet name+ "-servlet.xml"--> <init-param > <param-name>contextconfiglocation </param-name> <param-value></param-value> </init-param> <load-on-startup> 1</load-on-startup> </servlet
The first configuration is the initialization of the spring container to load the application file, then the SPRINGMVC Front Controller (dispatchservlet), which creates a new container in the spring container when the Dispatchservlet is configured. This is actually two containers, spring as a parent container, and SPRINGMVC as a child container. The SPRINGMVC child container is the one that can access the parent container Spring object.
We follow the official recommendation to classify different containers according to different business modules. Registering different types of bean:spring parent containers is responsible for registering the beans for all other non-@controller annotations, and SPRINGMVC is only responsible for registering the bean for @controller annotations. Make them accountability and clear the border. Configure as follows
1. Configure in Applicationcontext.xml:
< register non-@controller annotations in the spring container----
<context:component-scan base-package= "Com.hafiz.www" >
<context:exclude-filtertype= "Annotation" expression= "Org.springframework.stereotype.Controller"/>
</context:component-scan>
Configuration in 2.applicationcontext-mvc.xml
<!--only beans with @controller annotations are registered in the SPRINGMVC container--
<context:component-scan base-package= "Com.hafiz.www" use-default-filters= "false" >
<context:include-filtertype= "Annotation" expression= "Org.springframework.stereotype.Controller"/>
</context:component-scan>
Question 1 Whether the bean in simple interest is an instance or two instances in a parent-child container
A: Initialize two times, the Spring container initializes the BEAN,MVC container and initializes the bean, so it should be two beans.
Question 2 Why not load all the beans with spring
A: There is no object in the Springmvc container, there is no controller for the object, so when loading the processor, the adapter will not find the mapping object, mapping the relationship
Why not SPRINGMVC load all the objects
A: Many articles on the web say that sub-containers do not support AOP, in fact, this is not true. AOP is implemented because the relevant configuration of AOP is normally configured in the spring container, and if all the beans are migrated to the MVC configuration file, all of them are in a child container, which is equivalent to only one container. Disadvantage is not conducive to expansion.
Links: http://www.imooc.com/article/16155
Source: MU-Class Network
This article original published in Mu class network, reproduced please indicate the source, thank you for your cooperation
Links: http://www.imooc.com/article/16155
Source: MU-Class Network
This article original published in Mu class network, reproduced please indicate the source, thank you for your cooperation
Links: http://www.imooc.com/article/16155
Source: MU-Class Network
This article original published in Mu class network, reproduced please indicate the source, thank you for your cooperation
Spring and SPRINGMVC Parent-child container relationships