When a web application is launched, how do these 2 come into play? When are they both called. Can anybody explain with a practical scenario i.e by giving an example?
CodePudding user response:
I will answer to the best of my knowledge. There is an IOC container inside the spring framework. Creates and manages beans (objects) that I have registered -> Lower the coupling
For this purpose, a Servlet in the Front-Controller pattern called Dispatcher Servlet is placed in front. Each request from the client finds the appropriate bean and executes it.
1.Client -> Send request to web server
2. Dynamic web server -> pass to servlet container
3. Create a servlet container thread
4.Initialize DispatcherServlet (if servlet has not been created)
5. Call DispatcherServlet service() method in the created thread
6. Mapping controller lookup through HandlerMapping
Passing request to mapping controller via HandlerAdapter
8. Go to Developer Implementation Controller -> Service -> Repository...
CodePudding user response:
From my understand, i will simplify with the basic concept, you can refer the link for more detail.
DispatcherServlet is a special servlet which is used to handle/delegate request to special beans for different purpose... ( mapping request, validate, convert, render data ...)
https://docs.spring.io/spring-framework/docs/3.0.0.M4/reference/html/ch15s02.html
IoC container is spring container which manage spring beans (initialize/inject/destroy beans).
With annotation @Controller, @Component... They're spring bean, That beans will be created and managed by IoC.
https://www.baeldung.com/inversion-control-and-dependency-injection-in-spring