https://howtodoinjava.com/spring-mvc/contextloaderlistener-vs-dispatcherservlet/
DispatcherServlet – Child application contexts
DispatcherServlet
is essentially a Servlet (it extends HttpServlet
) whose primary purpose is to handle incoming web requests matching the configured URL pattern. It take an incoming URI and find the right combination of controller and view. So it is the front controller.
When you define a DispatcherServlet
in spring configuration, you provide an XML file with entries of controller classes, views mappings etc. using contextConfigLocation
attribute.
< servlet > < servlet-name >employee-services</ servlet-name > < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class > < init-param > < param-name >contextConfigLocation</ param-name > < param-value >classpath:employee-services-servlet.xml</ param-value > </ init-param > < load-on-startup >1</ load-on-startup > </ servlet > |
ContextLoaderListener – Root application context
ContextLoaderListener
creates the root application context and will be shared with child contexts created by all DispatcherServlet
contexts. You can have only one entry of this in web.xml
.
< listener > < listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class > </ listener > < context-param > < param-name >contextConfigLocation</ param-name > < param-value >/WEB-INF/spring/applicationContext.xml</ param-value > </ context-param > |
The context of ContextLoaderListener
contains beans that globally visible, like services, repositories, infrastructure beans, etc.
No comments:
Post a Comment