public class

DefaultAnnotationHandlerMapping

extends AbstractMapBasedHandlerMapping<K>
java.lang.Object
   ↳ org.springframework.context.support.ApplicationObjectSupport
     ↳ org.springframework.web.portlet.handler.AbstractHandlerMapping
       ↳ org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping<K>
         ↳ org.springframework.web.portlet.mvc.annotation.DefaultAnnotationHandlerMapping

Class Overview

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">
     ...
   </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). 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.

Summary

[Expand]
Inherited Constants
From interface org.springframework.core.Ordered
[Expand]
Inherited Fields
From class org.springframework.context.support.ApplicationObjectSupport
Public Constructors
DefaultAnnotationHandlerMapping()
Public Methods
void initApplicationContext()
Calls the registerHandlers method in addition to the superclass's initialization.
Protected Methods
boolean detectHandlerMethods(Class<?> handlerType, String beanName, RequestMapping typeMapping)
Derive portlet mode mappings from the handler's method-level mappings.
void detectHandlers()
Register all handlers specified in the Portlet mode map for the corresponding modes.
PortletMode getLookupKey(PortletRequest request)
Uses the current PortletMode as lookup key.
void validateHandler(Object handler, PortletRequest request)
Validate the given annotated handler against the current request.
void validateMapping(RequestMapping mapping, PortletRequest request)
Validate the given type-level mapping metadata against the current request, checking HTTP request method and parameter conditions.
[Expand]
Inherited Methods
From class org.springframework.web.portlet.handler.AbstractMapBasedHandlerMapping
From class org.springframework.web.portlet.handler.AbstractHandlerMapping
From class org.springframework.context.support.ApplicationObjectSupport
From class java.lang.Object
From interface org.springframework.context.ApplicationContextAware
From interface org.springframework.core.Ordered
From interface org.springframework.web.portlet.HandlerMapping

Public Constructors

public DefaultAnnotationHandlerMapping ()

Public Methods

public void initApplicationContext ()

Calls the registerHandlers method in addition to the superclass's initialization.

See Also

Protected Methods

protected boolean detectHandlerMethods (Class<?> handlerType, String beanName, RequestMapping typeMapping)

Derive portlet mode mappings from the handler's method-level mappings.

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

protected void detectHandlers ()

Register all handlers specified in the Portlet mode map for the corresponding modes.

Throws
BeansException if the handler couldn't be registered

protected PortletMode getLookupKey (PortletRequest request)

Uses the current PortletMode as lookup key.

Parameters
request current portlet request
Returns
  • the lookup key (never null)
Throws
Exception

protected void validateHandler (Object handler, PortletRequest request)

Validate the given annotated handler against the current request.

Throws
Exception

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.

Parameters
mapping the mapping metadata to validate
request current HTTP request
Throws
Exception if validation failed