I am trying to understand the plumbing between a Spring framework container and a Servlet. I am just getting started and believe that a Spring MVC application can work with servlets, portlets etc.,
When a spring application using servlets is launched, I believe the application's world begins with the creation of a spring container, whose main function (not main exactly, but something similar) creates the beans, stitches them up etc., It also then creates a servlet, the DispatcherServlet, which starts accepting connections and routes requests to other controllers in the spring application. Since the spring container does not actively manage the servlet, the DispatchServlet cannot be considered to be part of the spring container. Is the above understanding of mine correct ?
It would be great if anyone can shine more light on the plumbing between Spring framework and (say) and embedded servlet container such as Tomcat/getty. Thank You !
Spring itself isn't a container, its a framework. It does have an IoC container however and this container is built on beans and contexts. For instance in a web application, there are two contexts :
So to anwser your question, the dispatcher servlet is just a standard servlet but it has its own spring IoC context which is where controllers, view templates etc are declared and wired. if you look at the web.xml of a spring web application you see something like this...
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
This is just a standard servlet declaration and you provide it the xml file it is to use to create its own IoC context.
That clear things up?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With