cdmlib-remote-webapp configuration and bootstrapping

This page describes how spring mvc in cdmlib-remote-webapp is configured and how the application is being bootstrapped based on this configuration.


The bootstraping startst with the web.xml file in which the main application context and the DispatcherServlet context are configured to be picked up by the application container.

In a Spring MVC web application you will typically have a root WebApplicationContext via Spring's ContextLoaderListener and a child WebApplicationContext loaded via Spring's DispatcherServlet. This results in a parent-child context hierarchy where shared components and infrastructure configuration are declared in the root context and consumed in the child context by web-specific components.

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:

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

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 is 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

Java Spring configuration classes & packages

The CDM-Library has a couple of packages in which Java Spring configuration classes are located:


The package eu.etaxonomy.cdm.api.config contains spring configurations
which are loaded automatically into the root application context.
These classes are injected into the context via component scan.

Found in:

  • cdmlib/cdmlib-services


The package eu.etaxonomy.cdm.opt.config contains spring configurations
which can be loaded into the root WebApplicationContext loaded via
Spring's ContextLoaderListener, but which are optional.

This package must not be covered by a component scan. The bean(s) in here should be added
individually to the context

Found in:

  • cdmlib/cdmlib-remote


The package eu.etaxonomy.cdm.remote.config contains spring configurations
which are to be loaded into the child WebApplicationContext loaded via
Spring's DispatcherServlet. These classes are injected into the context via component scan.

Found in:

  • cdmlib/cdmlib-remote-webapp
  • cdmlib-remote


The package eu.etaxonomy.cdm.addon.config is an extension point where
addon-modules can place their Spring configuration classes so that the addon
can be bootstrapped. A component scan defined in cdmlib-remote-webapp will
find them.

Found in:

  • cdmlib/cdmlib-remote-webapp
  • cdm-vaadin

Participating classes and configuration files


The file /cdmlib-remote-webapp/src/main/webapp/WEB-INF/web.xml contains a listener entry and the configuration of the Spring dispatcher servlet:


<!-- Creates the Spring Container shared by all Servlets and Filters -->
    <!-- loads by default /WEB-INF/applicationContext.xml but this can be overridden above -->

Which creates the Spring Container shared by all Servlets and Filters. The ContextLoaderListener will load the main applicationContext configuration file /WEB-INF/applicationContext.xml


    <description>CDM Remote API</description>
    <!-- loads by default policy /WEB-INF/cdmlib-remote-servlet.xml  -->


The cdmlib-remote-webapp is configured using the MVC Java Config therefore the applicationContext.xml does not contain <mvc:annotation-driven/> but a <context:annotation-config /> entry:


<context:annotation-config />


This is the configuration of the MVC context of the cdmlib-remote servlet. It contains two parts, of which the first one lets spring find the CdmSpringMVCConfig class which is the main configuration bean for the MVC context. This class defines a couple of component scans to expose further beans to the context:

  Initialize SpringMVCConfig and its dependency SpringSwaggerConfig.
  All further component scans are defined in this mvc configuration class 
<context:component-scan base-package="eu/etaxonomy/cdm/remote/config" />

In addition to the CdmSpringMVCConfig class this component scan also covers the

The second part in this file is a conditional entry is an import directive which is only evaluated when the JVM option is supplied. This import causes the initialization of the HTTP Invoker based remoting services needed by the Taxonomic Editor to be able to connect to the CDM Server:

<!-- FIXME:Remoting Expose remoting services currently only for testing -->
<!-- Using Spring Beans Profile (>3.1) 
  only valid if it is at the end of the xml file activated by the vmarg -->
<beans profile="remoting">
  <import resource="classpath:/eu/etaxonomy/cdm/remoting-services.xml" />


The Java configuration bean for the spring MVC context, that is it is annotated with @Configuration but it has not the @EnableWebMvc annotation, since it 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 controllers need absolute method level RequestMapping values in some few cases. TODO

It enables swagger by the type annotation:


and defines a couple of component scans:

@ComponentScan(basePackages = {


This is also a spring java configuration class and thus annotated with @Configuration.
It provides the cdmlib-remote-webapp specific configuration for swagger.

Updated by Katja Luther 8 months ago · 42 revisions