The Spring Framework

org.springframework.web.servlet.mvc.annotation
Class DefaultAnnotationHandlerMapping

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.handler.AbstractHandlerMapping
              extended by org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
                  extended by org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping
                      extended by org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
All Implemented Interfaces:
ApplicationContextAware, Ordered, ServletContextAware, HandlerMapping

public class DefaultAnnotationHandlerMapping
extends AbstractDetectingUrlHandlerMapping

Implementation of the HandlerMapping interface that maps handlers based on HTTP paths expressed through the RequestMapping annotation at the type or method level.

Registered by default in DispatcherServlet on Java 5+. NOTE: If you define custom HandlerMapping beans in your DispatcherServlet context, you need to add a DefaultAnnotationHandlerMapping bean explicitly, since custom HandlerMapping beans replace the default mapping strategies. Defining a DefaultAnnotationHandlerMapping also allows for registering custom interceptors:

 <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
   <property name="interceptors">
     ...
   </property>
 </bean>
Annotated controllers are usually marked with the Controller stereotype at the type level. This is not strictly necessary when RequestMapping is applied at the type level (since such a handler usually implements the Controller interface). However, Controller is required for detecting RequestMapping annotations at the method level.

NOTE: Method-level mappings are only allowed to narrow the mapping expressed at the class level (if any). HTTP paths need to uniquely map onto specific handler beans, with any given HTTP path only allowed to be mapped onto one specific handler bean (not spread across multiple handler beans). It is strongly recommended to co-locate related handler methods into the same bean.

The AnnotationMethodHandlerAdapter is responsible for processing annotated handler methods, as mapped by this HandlerMapping. For RequestMapping at the type level, specific HandlerAdapters such as SimpleControllerHandlerAdapter apply.

Since:
2.5
Author:
Juergen Hoeller, Arjen Poutsma
See Also:
RequestMapping, AnnotationMethodHandlerAdapter

Field Summary
 
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
logger
 
Fields inherited from interface org.springframework.web.servlet.HandlerMapping
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
DefaultAnnotationHandlerMapping()
           
 
Method Summary
protected  String[] determineUrlsForHandler(String beanName)
          Checks for presence of the RequestMapping annotation on the handler class and on any of its methods.
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping
detectHandlers, initApplicationContext, setDetectHandlersInAncestorContexts
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
buildPathExposingHandler, exposePathWithinMapping, getHandlerInternal, getHandlerMap, getRootHandler, lookupHandler, registerHandler, registerHandler, setAlwaysUseFullPath, setLazyInitHandlers, setPathMatcher, setRootHandler, setUrlDecode, setUrlPathHelper
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping
adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, initInterceptors, setDefaultHandler, setInterceptors, setOrder
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, setServletContext
 
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, requiredContextClass, setApplicationContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAnnotationHandlerMapping

public DefaultAnnotationHandlerMapping()
Method Detail

determineUrlsForHandler

protected String[] determineUrlsForHandler(String beanName)
Checks for presence of the RequestMapping annotation on the handler class and on any of its methods.

Specified by:
determineUrlsForHandler in class AbstractDetectingUrlHandlerMapping
Parameters:
beanName - the name of the candidate bean
Returns:
the URLs determined for the bean, or null or an empty array if none

The Spring Framework

Copyright © 2002-2007 The Spring Framework.