A container is a context in which people can share something.
when the Spring
application starts, it first reads the web.xml
file and calls ContextLoaderListener
to create the Spring
container, which is what you call the parent container.
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
after Listener is created, start creating Servlet:
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
at this time this DispatcherServlet
begins to try to create ApplicationContext
of SpringMVC
. It first looks for ApplicationContext
of Spring
created by ContextLoaderListener
above, and then passes ApplicationContext
of Spring
as a parameter to ApplicationContext
setParent
of DispatcherServlet
.
because the Spring parent container of SpringMVC is specified when the child container is created, the son can find the father, so the Bean in the child container SpringMVC can call the service of the parent container, but the parent container does not know that the son exists (an irresponsible father), and the Bean in the parent container cannot call the service in the child container.
presumably there is no need to say much about the relationship between Servlet. Just go to the code
HttpServletBean
inherits HttpServlet
, and the init method is as follows
.
@Override
public final void init() throws ServletException {
// Let subclasses do whatever initialization they like.
initServletBean();
}
look at the subclass FrameworkServlet-sharpinitServletBean
method
not very clear
< H2 > excuse me, I'm here to find the answer to this question. < / H2 >