public class SimpleUrlHandlerMapping extends AbstractUrlHandlerMapping
HandlerMapping
interface to map 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 instances. Mappings to bean names can be set via the "mappings"
property, in a form accepted by the java.util.Properties
class,
like 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, e.g. a registered "/test" matches "/test", and
various Ant-style pattern matches, e.g. a registered "/t*" pattern matches
both "/test" and "/team", "/test/*" matches all paths under "/test",
"/test/**" matches all paths below "/test". For details, see the
PathPattern
javadoc.
logger
BEST_MATCHING_HANDLER_ATTRIBUTE, BEST_MATCHING_PATTERN_ATTRIBUTE, MATRIX_VARIABLES_ATTRIBUTE, PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, URI_TEMPLATE_VARIABLES_ATTRIBUTE
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor and Description |
---|
SimpleUrlHandlerMapping() |
Modifier and Type | Method and Description |
---|---|
java.util.Map<java.lang.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(java.util.Map<java.lang.String,java.lang.Object> urlMap)
Register all handlers specified in the URL map for the corresponding paths.
|
void |
setMappings(java.util.Properties mappings)
Map URL paths to handler bean names.
|
void |
setUrlMap(java.util.Map<java.lang.String,?> urlMap)
Set a Map with URL paths as keys and handler beans (or handler bean names)
as values.
|
getHandlerInternal, getHandlerMap, lookupHandler, registerHandler, registerHandler, setLazyInitHandlers, validateHandler
getCorsConfiguration, getCorsProcessor, getHandler, getOrder, getPathPatternParser, setCorsConfigurations, setCorsProcessor, setOrder, setUseCaseSensitiveMatch, setUseTrailingSlashMatch
getApplicationContext, getMessageSourceAccessor, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext
public void setMappings(java.util.Properties mappings)
Supports direct URL matches and Ant-style pattern matches. For syntax details,
see the PathPattern
javadoc.
mappings
- properties with URLs as keys and bean names as valuessetUrlMap(java.util.Map<java.lang.String, ?>)
public void setUrlMap(java.util.Map<java.lang.String,?> urlMap)
Supports direct URL matches and Ant-style pattern matches. For syntax details,
see the PathPattern
javadoc.
urlMap
- map with URLs as keys and beans as valuessetMappings(java.util.Properties)
public java.util.Map<java.lang.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 ApplicationObjectSupport
ApplicationContextException
- in case of initialization errorsBeansException
- if thrown by ApplicationContext methodsApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext)
protected void registerHandlers(java.util.Map<java.lang.String,java.lang.Object> urlMap) throws BeansException
urlMap
- Map with URL paths as keys and handler beans or bean names as valuesBeansException
- if a handler couldn't be registeredjava.lang.IllegalStateException
- if there is a conflicting handler registered