Cdmlib-remote-webappConfigurationAndBootstrapping » History » Revision 19
« Previous |
Revision 19/42
(diff)
| Next »
Andreas Kohlbecker, 11/26/2015 11:57 AM
cdmlib-remote-webapp configuration and bootstrapping¶
- Table of contents
- cdmlib-remote-webapp configuration and bootstrapping
This page describes how spring mvc in cdmlib-remote-webapp
is configured and whow the application is being bootstrapped based on this configuration.
Bootstrap¶
The bootstraping startst with the web.xml file in which the main application context and the DispatcherServlet context configured to be picked up by the application container.
Spring has support for hierarchical bean factories, so in the case of the spring mvc, the dispatcher servlet context is a child of the main application context:
Main application context (beans such as data sources, jpa configuration, business services) --> /WEB-INF/applicationContext.xml
- -child context-> dispatcher servlet context (MVC specific configuration, components, beans) --> /WEB-INF/cdmlib-remote-servlet.xml
If the servlet context was asked for a bean called "abc" it will look in the servlet context first, if it does not find it there it will look in the parent context, which is the application context.
For very detailed explanation on this topic, see http://stackoverflow.com/questions/15818047/spring-namespace-vs-contextconfiglocation-init-parameters-in-web-xml#answer-15825207
DispatcherServlet context¶
The DispatcherServlet builds the MVC context, handles all HTTP requests and delegates them to other components of the MVC architecture.
The configuration file for this context is the /WEB-INF/cdmlib-remote-servlet.xml
main application context¶
The main application context the the context in which the core cdm application with model, persistence and services is initialized.
The configuration file for this context is the /WEB-INF/applicationContext.xml
Participating classes and configuration files¶
CdmSpringMVCConfig¶
The main configuration class CdmSpringMVCConfig
directly subclasses @WebMvcConfigurationSupport@. "... An alternative more advanced option is to extend directly from this class and override methods as necessary remembering to add @Configuration to the subclass and @Bean to overridden @Bean methods. For more details see the Javadoc of @EnableWebMvc. ..."
The reason for this is that the method WebMvcConfigurationSupport.requestMappingHandlerMapping()
needs to be overridden in the @CdmSpringMVCConfig@. We may be able go without this method override once we no longer need CdmAntPathMatcher. which is only needed since the contollers need absolute method level RequestMapping values in some few cases. TODO
web.xml¶
The file /cdmlib-remote-webapp/src/main/webapp/WEB-INF/web.xml
contains an listener entry and the configuration of the Spring dispatcher servlet:
ContextLoaderListener:
<!-- Creates the Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <!-- loads by default /WEB-INF/applicationContext.xml but this can be overridden above --> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
Which creates the Spring Container shared by all Servlets and Filters. The ContextLoaderListener will load the main applicationContext configuration file /WEB-INF/applicationContext.xml
DispatcherServlet:
<servlet> <description>CDM Remote API</description> <servlet-name>cdmlib-remote</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> <!-- loads by default policy /WEB-INF/cdmlib-remote-servlet.xml --> </servlet>
applicationContext.xml¶
The cdmlib-remote-webapp
is configured using the MVC Java Config therefore the applicationContext.xml
does not contain a @ mvc:annotation-driven/ @ but an <context:annotation-config />
entry:
- @@ activates the annotations only on beans which have already been discovered and registered, see http://howtodoinjava.com/2014/07/19/spring-mvc-difference-between-contextannotation-config-vs-contextcomponent-scan/ for detailed explanations.
/WEB-INF/applicationContext.xml
<context:annotation-config />
cdmlib-remote-servlet.xml¶
Updated by Andreas Kohlbecker over 8 years ago · 19 revisions