org.springframework.web.servlet.handler.metadata
abstract public class: AbstractPathMapHandlerMapping [javadoc |
source]
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.handler.metadata.AbstractPathMapHandlerMapping
All Implemented Interfaces:
HandlerMapping, Ordered, ServletContextAware, ApplicationContextAware
Direct Known Subclasses:
CommonsPathMapHandlerMapping
Deprecated! as - of Spring 2.5, in favor of annotation-based request mapping.
To be removed in Spring 3.0.
Abstract implementation of the HandlerMapping interface that recognizes
metadata attributes of type PathMap on application Controllers and automatically
wires them into the current servlet's WebApplicationContext.
The path must be mapped to the relevant Spring DispatcherServlet in /WEB-INF/web.xml.
It's possible to have multiple PathMap attributes on the one controller class.
Controllers instantiated by this class may have dependencies on middle tier
objects, expressed via JavaBean properties or constructor arguments. These will
be resolved automatically.
You will normally use this HandlerMapping with at most one DispatcherServlet in your
web application. Otherwise you'll end with one instance of the mapped controller for
each DispatcherServlet's context. You might want this -- for example, if
one's using a .pdf mapping and a PDF view, and another a JSP view, or if
using different middle tier objects, but should understand the implications. All
Controllers with attributes will be picked up by each DispatcherServlet's context.
- author:
Rod - Johnson
- author:
Juergen - Hoeller
| Methods from org.springframework.web.servlet.handler.AbstractUrlHandlerMapping: |
|---|
|
buildPathExposingHandler, exposePathWithinMapping, getHandlerInternal, getHandlerMap, getPathMatcher, getRootHandler, lookupHandler, registerHandler, registerHandler, setAlwaysUseFullPath, setLazyInitHandlers, setPathMatcher, setRootHandler, setUrlDecode, setUrlPathHelper, validateHandler |
| Methods from org.springframework.web.servlet.handler.AbstractHandlerMapping: |
|---|
|
adaptInterceptor, extendInterceptors, getAdaptedInterceptors, getDefaultHandler, getHandler, getHandlerExecutionChain, getHandlerInternal, getOrder, initApplicationContext, initInterceptors, setDefaultHandler, setInterceptors, setOrder |
| Method from org.springframework.web.servlet.handler.metadata.AbstractPathMapHandlerMapping Detail: |
protected void detectAndCreateHandlers(ConfigurableListableBeanFactory beanFactory) throws BeansException {
try {
Class[] handlerClasses = getClassesWithPathMapAttributes();
if (logger.isDebugEnabled()) {
logger.debug("Found " + handlerClasses.length + " attribute-targeted handlers");
}
// for each Class returned by the Commons Attribute indexer
for (int i = 0; i < handlerClasses.length; i++) {
Class handlerClass = handlerClasses[i];
// Autowire the given handler class via AutowireCapableBeanFactory.
// Either autowires a constructor or by type, depending on the
// constructors available in the given class.
Object handler = beanFactory.createBean(handlerClass, this.autowireMode, this.dependencyCheck);
// We now have an "autowired" handler, that may reference beans in the
// application context. We now add the new handler to the factory.
// This isn't necessary for the handler to work, but is useful if we want
// to enumerate controllers in the factory etc.
beanFactory.registerSingleton(handlerClass.getName(), handler);
// There may be multiple paths mapped to this handler.
PathMap[] pathMaps = getPathMapAttributes(handlerClass);
registerHandler(pathMaps, handler);
}
}
catch (BeansException ex) {
throw ex;
}
catch (Exception ex) {
throw new BeanInitializationException("Could not retrieve PathMap attributes", ex);
}
} Deprecated!Look for all classes with a PathMap class attribute, instantiate them in
the owning ApplicationContext, and register them as MVC handlers usable
by the current DispatcherServlet. |
abstract protected Class[] getClassesWithPathMapAttributes() throws Exception Deprecated!
Use an attribute index to get a Collection of Class objects
with the required PathMap attribute. |
abstract protected PathMap[] getPathMapAttributes(Class handlerClass) throws Exception Deprecated!
Use Attributes API to find PathMap attributes for the given handler class.
We know there's at least one, as the getClassNamesWithPathMapAttributes
method return this class name. |
public void initApplicationContext() throws BeansException {
super.initApplicationContext();
if (!(getApplicationContext() instanceof ConfigurableApplicationContext)) {
throw new IllegalStateException(
"[" + getClass().getName() + "] needs to run in a ConfigurableApplicationContext");
}
ConfigurableListableBeanFactory beanFactory =
((ConfigurableApplicationContext) getApplicationContext()).getBeanFactory();
detectAndCreateHandlers(beanFactory);
} Deprecated!Calls the detectAndCreateHandlers method in addition
to the superclass's initialization. |
protected void registerHandler(PathMap[] pathMaps,
Object handler) throws IllegalStateException, BeansException {
for (int j = 0; j < pathMaps.length; j++) {
PathMap pathMap = pathMaps[j];
String path = pathMap.getUrl();
if (!path.startsWith("/")) {
path = "/" + path;
}
registerHandler(path, handler);
}
} Deprecated!Register the given handler for the URL paths indicated by the given PathMaps. |
public void setAutowireMode(int autowireMode) {
this.autowireMode = autowireMode;
} Deprecated!Set the autowire mode for handlers. This determines whether any automagical
detection and setting of bean references will happen.
Default is AUTOWIRE_AUTODETECT, which means either constructor autowiring or
autowiring by type (depending on the constructors available in the class). |
public void setAutowireModeName(String constantName) throws IllegalArgumentException {
setAutowireMode(constants.asNumber(constantName).intValue());
} Deprecated!Set the autowire mode for handlers, by the name of the corresponding constant
in the AutowireCapableBeanFactory interface, e.g. "AUTOWIRE_BY_NAME". |
public void setDependencyCheck(boolean dependencyCheck) {
this.dependencyCheck = dependencyCheck;
} Deprecated!Set whether to perform a dependency check for objects on autowired handlers.
Not applicable to autowiring a constructor, thus ignored there.
Default is "true". |