|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.context.support.ApplicationObjectSupport org.springframework.web.context.support.WebApplicationObjectSupport org.springframework.web.servlet.handler.AbstractHandlerMapping org.springframework.web.servlet.handler.AbstractUrlHandlerMapping org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping
public class ControllerClassNameHandlerMapping
Implementation of HandlerMapping
that follows a simple convention for
generating URL path mappings from the class names of registered
Controller
and
ThrowawayController
beans.
For simple Controller
implementations
(those that handle a single request type), the convention is to take the
short name
of the Class
,
remove the 'Controller' suffix if it exists and return the remaining text, lowercased,
as the mapping, with a leading /
. For example:
WelcomeController
-> /welcome*
HomeController
-> /home*
For MultiActionControllers
then a similar mapping is registered,
except that all sub-paths are registed using the trailing wildcard pattern /*
.
For example:
WelcomeController
-> /welcome/*
CatalogController
-> /catalog/*
For MultiActionController
it is often useful to use
this mapping strategy in conjunction with the
InternalPathMethodNameResolver
.
Controller
,
ThrowawayController
,
MultiActionController
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 | |
---|---|
ControllerClassNameHandlerMapping()
|
Method Summary | |
---|---|
protected void |
detectControllers()
Detect all the Controller and
ThrowawayController
beans registered in the ApplicationContext
and register a URL path mapping for each one based on rules defined here. |
protected String |
generatePathMapping(Class beanClass)
Generate the actual URL path for the given controller class. |
protected void |
initApplicationContext()
Calls the detectControllers() method in addition to the
superclass's initialization. |
protected boolean |
isEligibleForMapping(String beanName,
Class beanClass)
Determine whether the specified controller is excluded from this mapping. |
protected void |
registerController(String beanName,
Class beanClass)
Register the controller with the given name, as defined in the current application context. |
protected void |
registerControllers(Class controllerType)
Register all controllers of the given type, searching the current DispatcherServlet's ApplicationContext for matching beans. |
void |
setExcludedClasses(Class[] excludedClasses)
Specify controller classes that should be excluded from this mapping. |
void |
setExcludedPackages(String[] excludedPackages)
Specify Java packages that should be excluded from this mapping. |
Methods inherited from class org.springframework.web.servlet.handler.AbstractUrlHandlerMapping |
---|
exposePathWithinMapping, getHandlerInternal, getHandlerMap, lookupHandler, registerHandler, registerHandler, setAlwaysUseFullPath, setLazyInitHandlers, setPathMatcher, setRootHandler, setUrlDecode, setUrlPathHelper |
Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMapping |
---|
adaptInterceptor, getDefaultHandler, getHandler, 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 |
Methods inherited from interface org.springframework.web.servlet.HandlerMapping |
---|
getHandler |
Constructor Detail |
---|
public ControllerClassNameHandlerMapping()
Method Detail |
---|
public void setExcludedPackages(String[] excludedPackages)
Default is to exclude the entire "org.springframework.web.servlet.mvc"
package, including its subpackages, since none of Spring's out-of-the-box
Controller implementations is a reasonable candidate for this mapping strategy.
Such controllers are typically handled by a separate HandlerMapping,
e.g. a BeanNameUrlHandlerMapping
,
alongside this ControllerClassNameHandlerMapping for application controllers.
public void setExcludedClasses(Class[] excludedClasses)
protected void initApplicationContext()
detectControllers()
method in addition to the
superclass's initialization.
initApplicationContext
in class AbstractHandlerMapping
AbstractHandlerMapping.initInterceptors()
protected void detectControllers() throws BeansException
Controller
and
ThrowawayController
beans registered in the ApplicationContext
and register a URL path mapping for each one based on rules defined here.
BeansException
- if the controllers couldn't be obtained or registeredgeneratePathMapping(Class)
protected void registerControllers(Class controllerType) throws BeansException
controllerType
- the type of controller to search for
BeansException
- if the controllers couldn't be obtained or registeredprotected boolean isEligibleForMapping(String beanName, Class beanClass)
beanName
- the name of the controller beanbeanClass
- the concrete class of the controller bean
setExcludedPackages(java.lang.String[])
,
setExcludedClasses(java.lang.Class[])
protected void registerController(String beanName, Class beanClass) throws BeansException, IllegalStateException
beanName
- the name of the controller beanbeanClass
- the concrete class of the controller bean
BeansException
- if the controller couldn't be registered
IllegalStateException
- if there is a conflicting handler registeredApplicationObjectSupport.getApplicationContext()
protected String generatePathMapping(Class beanClass)
Subclasses may choose to customize the paths that are generated by overriding this method.
beanClass
- the controller bean class to generate a mapping for
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |