public class RouterHandlerMapping
extends org.springframework.web.servlet.handler.AbstractHandlerMapping
HandlerMapping
interface that maps handlers based on HTTP routes defined in a route
configuration file.
RouterHandlerMapping is not the default HandlerMapping registered in
DispatcherServlet in SpringMVC. You
need to declare and configure it in your DispatcherServlet context, by adding
a RouterHandlerMapping bean explicitly. RouterHandlerMapping needs the name
of the route configuration file (available in the application classpath); it
also allows for registering custom interceptors:
<bean class="org.resthub.web.springmvc.router.RouterHandlerMapping"> <property name="routeFiles"> <list> <value>bindingroutes.conf</value> <value>addroutes.conf</value> </list> </property> <property name="interceptors" > ... </property> </bean>
Annotated controllers should be marked with the Controller
stereotype at the type level. This is not strictly necessary because the
methodeInvoker will try to map the Controller.invoker anyway using the
current ApplicationContext. The RequestMapping is not taken into
account here.
RouterHandlerMapping loads routes configuration from a file for route
configuration syntax (the Router implementation is adapted from Play!
Framework http://www.playframework.org/documentation/1.0.3/routes#syntax).
Example:
GET /home PageController.showPage(id:'home') GET
/page/{id} PageController.showPage POST /customer/{<[0-9]+>customerid}
CustomerController.createCustomer
The RequestMappingHandlerAdapter is responsible for choosing and
invoking the right controller method, as mapped by this HandlerMapping.
AbstractHandlerMapping| Constructor and Description |
|---|
RouterHandlerMapping() |
| Modifier and Type | Method and Description |
|---|---|
protected Object |
getHandlerInternal(javax.servlet.http.HttpServletRequest request)
Resolves a HandlerMethod (of type RouterHandler) given the current HTTP
request, using the Router instance.
|
List<String> |
getRouteFiles()
Routes configuration Files names Injected by bean configuration (in
servlet.xml)
|
protected void |
initApplicationContext()
Inits Routes from route configuration file
|
boolean |
isAutoReloadEnabled()
Route files auto-reloading
Injected by bean configuration (in servlet.xml)
|
void |
reloadRoutesConfiguration()
Reload routes configuration at runtime.
|
void |
setAutoReloadEnabled(boolean autoReloadEnabled) |
void |
setRouteFiles(List<String> routeFiles) |
adaptInterceptor, detectMappedInterceptors, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getMappedInterceptors, getOrder, getPathMatcher, getUrlPathHelper, initInterceptors, setAlwaysUseFullPath, setDefaultHandler, setInterceptors, setOrder, setPathMatcher, setRemoveSemicolonContent, setUrlDecode, setUrlPathHelpergetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextpublic List<String> getRouteFiles()
public boolean isAutoReloadEnabled()
public void setAutoReloadEnabled(boolean autoReloadEnabled)
public void reloadRoutesConfiguration()
protected void initApplicationContext()
throws org.springframework.beans.BeansException
initApplicationContext in class org.springframework.web.servlet.handler.AbstractHandlerMappingorg.springframework.beans.BeansExceptionprotected Object getHandlerInternal(javax.servlet.http.HttpServletRequest request) throws Exception
getHandlerInternal in class org.springframework.web.servlet.handler.AbstractHandlerMappingrequest - the HTTP Servlet requestExceptionCopyright © 2010-2014. All Rights Reserved.