Class DefaultAnnotationHandlerMapping

  extended by
      extended by org.springframework.web.portlet.handler.AbstractHandlerMapping
          extended by org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping<PortletMode>
              extended by org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping
All Implemented Interfaces:
Aware, ApplicationContextAware, Ordered, HandlerMapping

public class DefaultAnnotationHandlerMapping
extends AbstractMapBasedHandlerMapping<PortletMode>

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

Registered by default in DispatcherPortlet on Java 5+. NOTE: If you define custom HandlerMapping beans in your DispatcherPortlet 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.portlet.mvc.annotation.DefaultAnnotationHandlerMapping">
   <property name="interceptors">
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). A portlet mode in combination with specific parameter conditions needs to uniquely map 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.

Juergen Hoeller
See Also:
RequestMapping, AnnotationMethodHandlerAdapter

Nested Class Summary
private static class DefaultAnnotationHandlerMapping.EventMappingPredicate
private static class DefaultAnnotationHandlerMapping.ParameterMappingPredicate
          Predicate that matches against parameter conditions.
private static class DefaultAnnotationHandlerMapping.ResourceMappingPredicate
Nested classes/interfaces inherited from class org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping
Field Summary
private  java.util.Map<java.lang.Class,RequestMapping> cachedMappings
Fields inherited from class
Fields inherited from interface org.springframework.core.Ordered
Constructor Summary
Method Summary
protected  boolean detectHandlerMethods(java.lang.Class<?> handlerType, java.lang.String beanName, RequestMapping typeMapping)
          Derive portlet mode mappings from the handler's method-level mappings.
protected  void detectHandlers()
          Register all handlers specified in the Portlet mode map for the corresponding modes.
protected  PortletMode getLookupKey(PortletRequest request)
          Uses the current PortletMode as lookup key.
 void initApplicationContext()
          Calls the registerHandlers method in addition to the superclass's initialization.
protected  void validateHandler(java.lang.Object handler, PortletRequest request)
          Validate the given annotated handler against the current request.
protected  void validateMapping(RequestMapping mapping, PortletRequest request)
          Validate the given type-level mapping metadata against the current request, checking HTTP request method and parameter conditions.
Methods inherited from class org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping
getHandlerInternal, registerHandler, registerHandler, registerHandlers, setLazyInitHandlers
Methods inherited from class org.springframework.web.portlet.handler.AbstractHandlerMapping
adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getOrder, initInterceptors, setApplyWebRequestInterceptorsToRenderPhaseOnly, setDefaultHandler, setInterceptors, setOrder
Methods inherited from class
getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, requiredContextClass, setApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


private final java.util.Map<java.lang.Class,RequestMapping> cachedMappings
Constructor Detail


public DefaultAnnotationHandlerMapping()
Method Detail


public void initApplicationContext()
                            throws BeansException
Calls the registerHandlers method in addition to the superclass's initialization.

initApplicationContext in class AbstractHandlerMapping
ApplicationContextException - in case of initialization errors
BeansException - if thrown by ApplicationContext methods
See Also:


protected void detectHandlers()
                       throws BeansException
Register all handlers specified in the Portlet mode map for the corresponding modes.

BeansException - if the handler couldn't be registered


protected boolean detectHandlerMethods(java.lang.Class<?> handlerType,
                                       java.lang.String beanName,
                                       RequestMapping typeMapping)
Derive portlet mode mappings from the handler's method-level mappings.

handlerType - the handler type to introspect
beanName - the name of the bean introspected
typeMapping - the type level mapping (if any)
true if at least 1 handler method has been registered; false otherwise


protected PortletMode getLookupKey(PortletRequest request)
                            throws java.lang.Exception
Uses the current PortletMode as lookup key.

Specified by:
getLookupKey in class AbstractMapBasedHandlerMapping<PortletMode>
request - current portlet request
the lookup key (never null)
java.lang.Exception - if key computation failed


protected void validateHandler(java.lang.Object handler,
                               PortletRequest request)
                        throws java.lang.Exception
Validate the given annotated handler against the current request.

See Also:
validateMapping(org.springframework.web.bind.annotation.RequestMapping, PortletRequest)


protected void validateMapping(RequestMapping mapping,
                               PortletRequest request)
                        throws java.lang.Exception
Validate the given type-level mapping metadata against the current request, checking HTTP request method and parameter conditions.

mapping - the mapping metadata to validate
request - current HTTP request
java.lang.Exception - if validation failed