Page 1 of 1

How BeanNameUrlHandlerMapping(Default) mapping resgistered ?

Posted: Wed Oct 29, 2014 12:01 pm
by yoga
Hello

Below is the method of spring's Dispatcher servlet. If we study this method we can find out if we specify the custom mapping then default mapping(BeanNameUrlHandlerMapping) provided my spring does not registered. This is happening in a separate project other then broadleaf. but in broadleaf BeanNameUrlHandlerMapping is also get registered. i saw it by puttin a debug point on it. I know others handler mapping also get registered but these define are in xml files.
but i did not find the definition of BeanNameUrlHandlerMapping and SimpleUrlHandlerMapping. in xml files

please tell me how these are registered.

Code: Select all

private void initHandlerMappings(ApplicationContext context) {
      this.handlerMappings = null;

      if (this.detectAllHandlerMappings) {
         // Find all HandlerMappings in the ApplicationContext, including ancestor contexts.
         Map<String, HandlerMapping> matchingBeans =
               [quote]BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerMapping.class, true, false);[/quote]
         if (!matchingBeans.isEmpty()) {
            this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
            // We keep HandlerMappings in sorted order.
            OrderComparator.sort(this.handlerMappings);
         }
      }
      else {
         try {
            HandlerMapping hm = context.getBean(HANDLER_MAPPING_BEAN_NAME, HandlerMapping.class);
            this.handlerMappings = Collections.singletonList(hm);
         }
         catch (NoSuchBeanDefinitionException ex) {
            // Ignore, we'll add a default HandlerMapping later.
         }
      }

      // Ensure we have at least one HandlerMapping, by registering
      // a default HandlerMapping if no other mappings are found.
      if (this.handlerMappings == null) {
         this.handlerMappings = getDefaultStrategies(context, HandlerMapping.class);
         if (logger.isDebugEnabled()) {
            logger.debug("No HandlerMappings found in servlet '" + getServletName() + "': using default");
         }
      }
   }

Re: How BeanNameUrlHandlerMapping(Default) mapping resgistered ?

Posted: Wed Nov 05, 2014 5:15 pm
by phillipuniverse
They are registered by @Controller and @RequestMapping annotations on the java classes themselves. If you add any custom controllers, they must be scanned in the servlet application context, meaning, they need to be scanned in applicationContext-servlet.xml. Last time I checked, Spring's dispatcher servlet did not try to look for @Controller's defined in the root application context.

Re: How BeanNameUrlHandlerMapping(Default) mapping resgistered ?

Posted: Sat Nov 08, 2014 1:55 pm
by yoga
ok Let me debug more..... :geek: