The Spring Framework

org.springframework.web.servlet.handler
Class BeanNameUrlHandlerMapping

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.BeanNameUrlHandlerMapping
All Implemented Interfaces:
ApplicationContextAware, Ordered, ServletContextAware, HandlerMapping

public class BeanNameUrlHandlerMapping
extends AbstractUrlHandlerMapping

Implementation of the HandlerMapping interface that map from URLs to beans with names that start with a slash ("/"), similar to how Struts maps URLs to action names.

This is the default implementation used by the DispatcherServlet, but it is somewhat naive. A SimpleUrlHandlerMapping or a custom handler mapping should be used by preference.

The mapping is from URL to bean name. Thus an incoming URL "/foo" would map to a handler named "/foo", or to "/foo /foo2" in case of multiple mappings to a single handler. Note: In XML definitions, you'll need to use an alias name="/foo" in the bean definition, as the XML id may not contain slashes.

Supports direct matches (given "/test" -> registered "/test") and "*" matches (given "/test" -> registered "/t*"). Note that the default is to map within the current servlet mapping if applicable; see the "alwaysUseFullPath" property for details. For details on the pattern options, see the AntPathMatcher javadoc.

Author:
Rod Johnson, Juergen Hoeller
See Also:
SimpleUrlHandlerMapping

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
BeanNameUrlHandlerMapping()
           
 
Method Summary
protected  void detectHandlers()
          Register all handlers found in the current ApplicationContext.
protected  String[] determineUrlsForHandler(String beanName)
          Check name and aliases of the given bean for URLs, detected by starting with "/".
 void initApplicationContext()
          Calls the detectHandlers() method in addition to the superclass's initialization.
 void setDetectHandlersInAncestorContexts(boolean detectHandlersInAncestorContexts)
          Set whether to detect handler beans in ancestor ApplicationContexts.
 
Methods inherited from class org.springframework.web.servlet.handler.AbstractUrlHandlerMapping
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

BeanNameUrlHandlerMapping

public BeanNameUrlHandlerMapping()
Method Detail

setDetectHandlersInAncestorContexts

public void setDetectHandlersInAncestorContexts(boolean detectHandlersInAncestorContexts)
Set whether to detect handler beans in ancestor ApplicationContexts.

Default is "false": Only handler beans in the current ApplicationContext will be detected, that is, only in the context that this BeanNameUrlHandlerMapping itself is defined in (typically the current DispatcherServlet's context).

Switch this flag on to detect handler beans in ancestor contexts (typically the Spring root WebApplicationContext) as well.


initApplicationContext

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

Overrides:
initApplicationContext in class AbstractHandlerMapping
Throws:
ApplicationContextException - in case of initialization errors
See Also:
AbstractHandlerMapping.extendInterceptors(java.util.List), AbstractHandlerMapping.initInterceptors()

detectHandlers

protected void detectHandlers()
                       throws BeansException
Register all handlers found in the current ApplicationContext. Any bean whose name appears to be a URL is considered a handler.

Throws:
BeansException - if the handler couldn't be registered
See Also:
determineUrlsForHandler(java.lang.String)

determineUrlsForHandler

protected String[] determineUrlsForHandler(String beanName)
Check name and aliases of the given bean for URLs, detected by starting with "/".

Parameters:
beanName - the name of the candidate bean
Returns:
the URLs determined for the bean, or an empty array if none

The Spring Framework

Copyright © 2002-2007 The Spring Framework.