Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5722

Remove bean definitions for DefaultAnnotationHandlerMapping

    XMLWordPrintable

    Details

    • Type: Epic
    • Status: Closed
    • Priority: Should
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Complexity:
      Low
    • Epic Name:
      Migrate away from DefaultAnnotationHandlerMapping

      Description

      With the recent upgrade to Spring 5, one problem that has arisen is that the DefaultAnnotationHandlerMapping class has been removed from Spring MVC. This class has been deprecated since Spring 3.2 in favour of the RequestMappingHandlerMapping, but is still used extensively throughout our community modules. We should therefore migrate our code to no longer make use of this class.

      OpenMRS seems to use DefaultAnnotationHandlerMapping in two ways:

      1. In some instances, it's simply defined as a bean in the corresponding webModuleApplicationContext.xml like this:

      <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
      

      In these instances, the mapping should be removed from the webModuleApplicationContext.xml and inserted into a Spring Configuration class in the Omod, similar to what was done in this commit. At a minimum, this class should contain:

      /**
       * The DefaultAnnotationHandlerMapping class was deprecated and eventually removed in Spring 5
       * The recommended replacement class RequestMappingHandlerMapping was introduced in Spring 3.1.0
       * which is not available on OpenMRS platform versions 1.9.x and 1.1.0.x which run Spring 3.0.5
       * That's why we can't just statically replace this class in the webModuleApplicationContext.xml
       * file.
       */
      @Bean
      public AbstractHandlerMapping getHandlerMapping() throws Exception {
      
      	Class<?> clazz;
      	if (ModuleUtil.compareVersion(OpenmrsConstants.OPENMRS_VERSION_SHORT, "2.4") < 0) {
      		clazz = Context.loadClass("org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping");
      	}
      	else {
      		clazz = Context.loadClass("org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping");
      	}
      
      	return (AbstractHandlerMapping) clazz.newInstance();
      }
      

      2. In other instances, DefaultAnnotationHandlerMapping is used directly in code, albeit primarily in tests. In these cases, we should investigate whether the code is necessary and if it is whether it can be successfully swapped for an implementation using RequestMappingHandlerMapping.

      For some background see this Talk thread

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sharif Sharif Magembe
              Reporter:
              ibacher Ian Bacher
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: