In Figure 14-1 above, the WebApplicationContext linking with DispatcherServlet is created from files set as initialization parameter in this servlet as shown in Listing 14-1 below. Similarly the second WebApplicationContext linking with the DispatcherServlet’s WebApplicationContext is loaded from files supplied to the Spring’s ContextLoaderListene as shown in Listing 14-1 below.
Listing 14-2. Context configuration file declared as initialization parameter in DispatcherServlet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
… <servlet> <servlet-name>sample</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/sample-config.xml /WEB-INF/spring/webflow-config.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sample</servlet-name> <url-pattern>/app/*</url-pattern> </servlet-mapping> … |
Listing 14-3. Loading context configuration file using Spring’s ContextLoaderListener
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
… <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/app-config.xml /WEB-INF/spring/security-config.xml </param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> … |
You also have a provision of mixing/loading all the Spring’s configuration file using the DispatcherServlet itself as shown in Listing 14-4 below.
Listing 14-4. Creation of one WebApplicationContext by allowing DispatcherServlet to load all the Spring configuration file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
… <servlet> <servlet-name>sample</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/*.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>sample</servlet-name> <url-pattern>/app/*</url-pattern> </servlet-mapping> … |
In addition to the core role of DispatcherServlet acting as Front Controller in Spring MVC, it does many things inherently and provides various extension points by which to configure it according to application requirements. For doing this it contains special beans which processes the request and renders appropriate views. According to your application requirement you can choose these special beans and configure it accordingly. If you don’t do this, Spring MVC uses default beans. The special bean types can be summarized as shown in Table 14-1 below (Referred from Spring documentation). All the bean types shown in the table below resides in org.springframework.web.servlet package.
Page Visitors: 7466

Tomcy John

Latest posts by Tomcy John (see all)
- A Guide to Continuous Improvement for Architects - February 2, 2023
- Cloud-first Architecture Strategy - January 26, 2023
- Architecture Strategy and how to create One - January 24, 2023