The difference between Spring IOC container and Spring MVC IOC container

 web.xml

<context-param>
    <param-name>contextConfigLocation</param-name>
   <!-- 指定加载application配置文件 -->
    <param-value>classpath:spring/application.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 配置SpringMVC -->
<servlet>
  <servlet-name>usermanage</servlet-name>
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <init-param>
    <!- Specifies the spring-mvc external profile load -> 
    <param-name> the contextConfigLocation </ param-name>
    <param-value> CLASSPATH: Spring / springmvc.xml </ param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
</servlet>

 

Servlet: a container for the child represented by a spring-mvc

DispatcherServlet context initialization IOC will build their own context, to hold Spring mvc related bean.

A front-end controller DispatcherServlet

DispatcherServlet specially when listening for requests distal used (and the organization responsible for coordinating the various components to complete and return a response request processing work)

Receives the current request, the DispatcherServlet removed from the container all instances HandlerMapping traversal, each based HandlerMapping request information through their own implementation class to find a way (method, such as the Controller) Handler will process the request

 

context-param: a container vessel on behalf of the spring itself, spring-mvc can be understood as a child container inherited from the container, spring container is the topmost parent class vessel, with the same inherited principle of java

 

The IOC SpringMVC bean container can reference Spring IOC container bean

Conversely Spring IOC container bean Spring MVC IOC can not be referenced in the bean container because:

 

Spring MVC IOC Spring IOC container vessel is a sub-class, subclass can refer to the parent, the parent class is not referenced subclass.

 

From a software perspective, the, Spring MVC is the presentation layer can call the service layer, business layer can not be called the presentation layer.

 

When the server parses the web.xml due listener is listening, it will give priority to initialize the spring container, only after the initialization spring-mvc container.

Guess you like

Origin www.cnblogs.com/Esummer/p/11791468.html