In which scenarios, we need multiple Dispatcher-Servlets
?
Can anyone please tell me the use cases of multiple Dispat
From Documentation
A web application can define any number of DispatcherServlets. Each servlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener, if any, will be shared.
Simple answer is to have DispatcherServlet's functionality in several forms
DispatcherServlet
Declaring Multiple dispatcher servlets
Consider we have two dispatcher servlets(DS) where DS1, DS2 are configured with different url patterns(**.simple, **.beanName
) and they uses different dispatcher servlet configuration provided as given below.
DispatcherServlet - simpleUrlHandlerDispatcherServlet
contextConfigLocation - /WEB-INF/simpleUrlHandlerMapping.xml
*.simple
DispatcherServlet - beanNameUrlHandlerDispatcherServlet
contextConfigLocation - /WEB-INF/beanNameUrlHandlerMapping.xml
*.beanName
Advantage 1: We can have different HandlerMapping for different set of URL
DS1 bean name url handler mapping configuration
DS2 simple url handler mapping configuration
simpleHello
simpleHi
Advantage 2: We can have different view resolver for different set of URL's.
InternalResourceViewResolver for DS1
where it deals with only prefix + returned String + suffix
.
TilesViewResolver for DS2
its implementation provided by apache tiles which is a layout/skeleton based plugin high level functionality as given below.
Or if we use TilesViewResolver with different layout for different set of URL's
anonymous user - different layout
logged in user - different layout
Advantage 3: We can have different theme resolver for different set of URL's.
These resolver continuously monitors cookie/session to resolve theme and serves stylesheet/theme qualified (as given in below image). Below given just an example for outcome of CookieThemeResolver.
Note: This is not about theme configuration but about theme resolver configuration.
Advantage 4: We can have different locale resolver for different set of URL's.
These resolver continuously monitors cookie/session/accept-header to resolve locale and loads application message qualified(as given in below image). Below given just an example for outcome of CookieLocaleResolver.
Note: This is not about locale configuration but about locale resolver configuration.