public class SimpleUrlHandlerMapping extends AbstractUrlHandlerMapping
HandlerMapping
interface that maps from URLs to request handler beans. Supports both mapping to bean
instances and mapping to bean names; the latter is required for non-singleton handlers.
The "urlMap" property is suitable for populating the handler map with bean references, e.g. via the map element in XML bean definitions.
Mappings to bean names can be set via the "mappings" property, in a form
accepted by the java.util.Properties
class, as follows:
/welcome.html=ticketController /show.html=ticketController
The syntax is PATH=HANDLER_BEAN_NAME
. If the path doesn't begin
with a slash, one is prepended.
Supports direct matches (given "/test" -> registered "/test") and "*"
pattern 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 on the
pattern options, see the AntPathMatcher
javadoc.
setMappings(java.util.Properties)
,
setUrlMap(java.util.Map<java.lang.String, ?>)
,
BeanNameUrlHandlerMapping
logger
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, INTROSPECT_TYPE_LEVEL_MAPPING, LOOKUP_PATH, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
SimpleUrlHandlerMapping()
Create a
SimpleUrlHandlerMapping with default settings. |
SimpleUrlHandlerMapping(Map<String,?> urlMap)
Create a
SimpleUrlHandlerMapping using the supplied URL map. |
SimpleUrlHandlerMapping(Map<String,?> urlMap,
int order)
Create a
SimpleUrlHandlerMapping using the supplied URL map and order. |
Modifier and Type | Method and Description |
---|---|
Map<String,?> |
getUrlMap()
Allow Map access to the URL path mappings, with the option to add or
override specific entries.
|
void |
initApplicationContext()
Calls the
registerHandlers(java.util.Map<java.lang.String, java.lang.Object>) method in addition to the
superclass's initialization. |
protected void |
registerHandlers(Map<String,Object> urlMap)
Register all handlers specified in the URL map for the corresponding paths.
|
void |
setMappings(Properties mappings)
Map URL paths to handler bean names.
|
void |
setUrlMap(Map<String,?> urlMap)
Set a Map with URL paths as keys and handler beans (or handler bean names)
as values.
|
buildPathExposingHandler, exposePathWithinMapping, exposeUriTemplateVariables, getHandlerInternal, getHandlerMap, getRootHandler, lookupHandler, match, registerHandler, registerHandler, setLazyInitHandlers, setRootHandler, setUseTrailingSlashMatch, supportsTypeLevelMappings, useTrailingSlashMatch, validateHandler
adaptInterceptor, detectMappedInterceptors, extendInterceptors, formatMappingName, getAdaptedInterceptors, getCorsConfiguration, getCorsHandlerExecutionChain, getCorsProcessor, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, hasCorsConfigurationSource, initInterceptors, setAlwaysUseFullPath, setBeanName, setCorsConfigurations, setCorsConfigurationSource, setCorsProcessor, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelper
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
getApplicationContext, getMessageSourceAccessor, obtainApplicationContext, requiredContextClass, setApplicationContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getHandler
public SimpleUrlHandlerMapping()
SimpleUrlHandlerMapping
with default settings.public SimpleUrlHandlerMapping(Map<String,?> urlMap)
SimpleUrlHandlerMapping
using the supplied URL map.urlMap
- map with URL paths as keys and handler beans (or handler
bean names) as valuessetUrlMap(Map)
public SimpleUrlHandlerMapping(Map<String,?> urlMap, int order)
SimpleUrlHandlerMapping
using the supplied URL map and order.urlMap
- map with URL paths as keys and handler beans (or handler
bean names) as valuesorder
- the order value for this SimpleUrlHandlerMapping
setUrlMap(Map)
,
AbstractHandlerMapping.setOrder(int)
public void setMappings(Properties mappings)
Supports direct URL matches and Ant-style pattern matches. For syntax
details, see the AntPathMatcher
javadoc.
mappings
- properties with URLs as keys and bean names as valuessetUrlMap(java.util.Map<java.lang.String, ?>)
public void setUrlMap(Map<String,?> urlMap)
Supports direct URL matches and Ant-style pattern matches. For syntax
details, see the AntPathMatcher
javadoc.
urlMap
- map with URLs as keys and beans as valuessetMappings(java.util.Properties)
public Map<String,?> getUrlMap()
Useful for specifying entries directly, for example via "urlMap[myKey]". This is particularly useful for adding or overriding entries in child bean definitions.
public void initApplicationContext() throws BeansException
registerHandlers(java.util.Map<java.lang.String, java.lang.Object>)
method in addition to the
superclass's initialization.initApplicationContext
in class AbstractHandlerMapping
ApplicationContextException
- in case of initialization errorsBeansException
- if thrown by ApplicationContext methodsAbstractHandlerMapping.extendInterceptors(java.util.List)
,
AbstractHandlerMapping.initInterceptors()
protected void registerHandlers(Map<String,Object> urlMap) throws BeansException
urlMap
- a Map with URL paths as keys and handler beans or bean names as valuesBeansException
- if a handler couldn't be registeredIllegalStateException
- if there is a conflicting handler registered