- 浏览: 980030 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
看这篇文章之前,最好先看下面这篇,以便更好的理解handlerAdapters初始化所做的事情
Spring的RequestMappingHandlerMapping详解:http://donald-draper.iteye.com/blog/2326294
下面,我们来看DispatcherServlet的handlerAdapters初始化所做的事情
//Spring日志追踪我们可以发现,DispatcherServletd的处理适配器
下面我们来看一下RequestMappingHandlerAdapter
下面在来看一下
RequestMappingHandlerAdapter如何处理请求的
在DispatcherServlet的请求处理函数
上面的handle函数实际上是调用的AbstractHandlerMethodAdapter的方法handle
回到RequestMappingHandlerAdapter
//InvocableHandlerMethod
//HandlerMethod
//MethodParameter
总结:
从上面我们可以看出,RequestMappingHandlerAdapter主要是解决请求的,会话,请求头部处理,数据的绑定等,然后从容器中,获取handlerMethod,处理业务逻辑,获取数据,并渲染视图,返回。
Spring的RequestMappingHandlerMapping详解:http://donald-draper.iteye.com/blog/2326294
下面,我们来看DispatcherServlet的handlerAdapters初始化所做的事情
public class DispatcherServlet extends FrameworkServlet { public DispatcherServlet(WebApplicationContext webApplicationContext) { super(webApplicationContext); detectAllHandlerMappings = true; detectAllHandlerAdapters = true; detectAllHandlerExceptionResolvers = true; detectAllViewResolvers = true; throwExceptionIfNoHandlerFound = false; cleanupAfterInclude = true; } //初始化控制器映射 private void initHandlerMappings(ApplicationContext context) { handlerMappings = null; if(detectAllHandlerMappings) { Map matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, org/springframework/web/servlet/HandlerMapping, true, false); if(!matchingBeans.isEmpty()) { //List<HashMap<String,HandlerMapping>>,Key为beanName,value值为HandlerMapping实例 handlerMappings = new ArrayList(matchingBeans.values()); OrderComparator.sort(handlerMappings); } } } //初始化控制器方法适配器 private void initHandlerAdapters(ApplicationContext context) { handlerAdapters = null; if(detectAllHandlerAdapters) { Map matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, org/springframework/web/servlet/HandlerAdapter, true, false); if(!matchingBeans.isEmpty()) { //List<HashMap<String,HandlerAdapter>>,Key为beanName,value值为HandlerAdapter实例 handlerAdapters = new ArrayList(matchingBeans.values()); OrderComparator.sort(handlerAdapters); } } } private List handlerMappings;//List<HashMap<String,HandlerMapping>>,Key为beanName,value值为HandlerMapping实例 private List handlerAdapters;//List<HashMap<String,HandlerAdapter>>,Key为beanName,value值为HandlerAdapter实例 private List handlerExceptionResolvers; private List viewResolvers; static { try { //加载默认配置文件 ClassPathResource resource = new ClassPathResource("DispatcherServlet.properties", org/springframework/web/servlet/DispatcherServlet); defaultStrategies = PropertiesLoaderUtils.loadProperties(resource); } } }
//Spring日志追踪我们可以发现,DispatcherServletd的处理适配器
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter
下面我们来看一下RequestMappingHandlerAdapter
public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware, InitializingBean { //待bean属性初始化完,初始化一些ArgumentResolvers public void afterPropertiesSet() { if(argumentResolvers == null) { List resolvers = getDefaultArgumentResolvers(); argumentResolvers = (new HandlerMethodArgumentResolverComposite()).addResolvers(resolvers); } if(initBinderArgumentResolvers == null) { List resolvers = getDefaultInitBinderArgumentResolvers(); initBinderArgumentResolvers = (new HandlerMethodArgumentResolverComposite()).addResolvers(resolvers); } if(returnValueHandlers == null) { List handlers = getDefaultReturnValueHandlers(); returnValueHandlers = (new HandlerMethodReturnValueHandlerComposite()).addHandlers(handlers); } //初始化控制器增强处理,包括方法 initControllerAdviceCache(); } //获取默认的ArgumentResolvers private List getDefaultArgumentResolvers() { List resolvers = new ArrayList(); //@RequestParam resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); resolvers.add(new RequestParamMapMethodArgumentResolver()); //@PathVariable resolvers.add(new PathVariableMethodArgumentResolver()); resolvers.add(new PathVariableMapMethodArgumentResolver()); //@MatrixVariable resolvers.add(new MatrixVariableMethodArgumentResolver()); resolvers.add(new MatrixVariableMapMethodArgumentResolver()); //@ModelAttribute resolvers.add(new ServletModelAttributeMethodProcessor(false)); //@ResponseBody resolvers.add(new RequestResponseBodyMethodProcessor(getMessageConverters())); //@RequestPart resolvers.add(new RequestPartMethodArgumentResolver(getMessageConverters())); //@RequestHeader resolvers.add(new RequestHeaderMethodArgumentResolver(getBeanFactory())); resolvers.add(new RequestHeaderMapMethodArgumentResolver()); //@CookieValue resolvers.add(new ServletCookieValueMethodArgumentResolver(getBeanFactory())); //@Value resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory())); resolvers.add(new ServletRequestMethodArgumentResolver()); resolvers.add(new ServletResponseMethodArgumentResolver()); resolvers.add(new HttpEntityMethodProcessor(getMessageConverters())); resolvers.add(new RedirectAttributesMethodArgumentResolver()); resolvers.add(new ModelMethodProcessor()); resolvers.add(new MapMethodProcessor()); resolvers.add(new ErrorsMethodArgumentResolver()); resolvers.add(new SessionStatusMethodArgumentResolver()); resolvers.add(new UriComponentsBuilderMethodArgumentResolver()); if(getCustomArgumentResolvers() != null) resolvers.addAll(getCustomArgumentResolvers()); resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true)); resolvers.add(new ServletModelAttributeMethodProcessor(true)); return resolvers; } //获取默认的InitBinderArgumentResolvers private List getDefaultInitBinderArgumentResolvers() { List resolvers = new ArrayList(); resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false)); resolvers.add(new RequestParamMapMethodArgumentResolver()); resolvers.add(new PathVariableMethodArgumentResolver()); resolvers.add(new PathVariableMapMethodArgumentResolver()); resolvers.add(new MatrixVariableMethodArgumentResolver()); resolvers.add(new MatrixVariableMapMethodArgumentResolver()); resolvers.add(new ExpressionValueMethodArgumentResolver(getBeanFactory())); resolvers.add(new ServletRequestMethodArgumentResolver()); resolvers.add(new ServletResponseMethodArgumentResolver()); if(getCustomArgumentResolvers() != null) resolvers.addAll(getCustomArgumentResolvers()); resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), true)); return resolvers; } //获取默认的ReturnValueHandlers private List getDefaultReturnValueHandlers() { List handlers = new ArrayList(); handlers.add(new ModelAndViewMethodReturnValueHandler()); handlers.add(new ModelMethodProcessor()); handlers.add(new ViewMethodReturnValueHandler()); handlers.add(new HttpEntityMethodProcessor(getMessageConverters(), contentNegotiationManager)); handlers.add(new HttpHeadersReturnValueHandler()); handlers.add(new CallableMethodReturnValueHandler()); handlers.add(new DeferredResultMethodReturnValueHandler()); handlers.add(new AsyncTaskMethodReturnValueHandler(beanFactory)); handlers.add(new ModelAttributeMethodProcessor(false)); handlers.add(new RequestResponseBodyMethodProcessor(getMessageConverters(), contentNegotiationManager)); handlers.add(new ViewNameMethodReturnValueHandler()); handlers.add(new MapMethodProcessor()); if(getCustomReturnValueHandlers() != null) handlers.addAll(getCustomReturnValueHandlers()); if(!CollectionUtils.isEmpty(getModelAndViewResolvers())) handlers.add(new ModelAndViewResolverMethodReturnValueHandler(getModelAndViewResolvers())); else handlers.add(new ModelAttributeMethodProcessor(true)); return handlers; } private List customArgumentResolvers; private HandlerMethodArgumentResolverComposite argumentResolvers; private HandlerMethodArgumentResolverComposite initBinderArgumentResolvers; private List customReturnValueHandlers; private HandlerMethodReturnValueHandlerComposite returnValueHandlers; private List modelAndViewResolvers; private ContentNegotiationManager contentNegotiationManager; private List messageConverters; private WebBindingInitializer webBindingInitializer; private AsyncTaskExecutor taskExecutor; private Long asyncRequestTimeout; private CallableProcessingInterceptor callableInterceptors[]; private DeferredResultProcessingInterceptor deferredResultInterceptors[]; private boolean ignoreDefaultModelOnRedirect; private int cacheSecondsForSessionAttributeHandlers; private boolean synchronizeOnSession; private SessionAttributeStore sessionAttributeStore; private ParameterNameDiscoverer parameterNameDiscoverer; private ConfigurableBeanFactory beanFactory; private final Map sessionAttributesHandlerCache = new ConcurrentHashMap(64); private final Map initBinderCache = new ConcurrentHashMap(64); private final Map initBinderAdviceCache = new LinkedHashMap(); private final Map modelAttributeCache = new ConcurrentHashMap(64); private final Map modelAttributeAdviceCache = new LinkedHashMap(); public static final org.springframework.util.ReflectionUtils.MethodFilter INIT_BINDER_METHODS = new org.springframework.util.ReflectionUtils.MethodFilter() { //查看method是否带有@InitBinder public boolean matches(Method method) { return AnnotationUtils.findAnnotation(method, org/springframework/web/bind/annotation/InitBinder) != null; } }; public static final org.springframework.util.ReflectionUtils.MethodFilter MODEL_ATTRIBUTE_METHODS = new org.springframework.util.ReflectionUtils.MethodFilter() { //查看method是否带有@RequestMapping和@ModelAttribute public boolean matches(Method method) { return AnnotationUtils.findAnnotation(method, org/springframework/web/bind/annotation/RequestMapping) == null && AnnotationUtils.findAnnotation(method, org/springframework/web/bind/annotation/ModelAttribute) != null; } }; }
下面在来看一下
RequestMappingHandlerAdapter如何处理请求的
在DispatcherServlet的请求处理函数
protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception { mv = ha.handle(processedRequest, response, mappedHandler.getHandler()); }
上面的handle函数实际上是调用的AbstractHandlerMethodAdapter的方法handle
public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator implements HandlerAdapter, Ordered { //处理请求 public final ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { //委托给handleInternal return handleInternal(request, response, (HandlerMethod)handler); } //请求内部处理,留个子类RequestMappingHandlerAdapter扩展 protected abstract ModelAndView handleInternal(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, HandlerMethod handlermethod) throws Exception; }
回到RequestMappingHandlerAdapter
public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter implements BeanFactoryAware, InitializingBean { //请求内部处理 protected final ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { HttpSession session; //获取handlerMethod的会话属性,并检查请求方法是否支持 if(getSessionAttributesHandler(handlerMethod).hasSessionAttributes()) checkAndPrepare(request, response, cacheSecondsForSessionAttributeHandlers, true); else checkAndPrepare(request, response, true); if(!synchronizeOnSession) break MISSING_BLOCK_LABEL_85; session = request.getSession(false); if(session == null) break MISSING_BLOCK_LABEL_85; Object mutex = WebUtils.getSessionMutex(session); Object obj = mutex; JVM INSTR monitorenter ; //委托给invokeHandleMethod return invokeHandleMethod(request, response, handlerMethod); } private ModelAndView invokeHandleMethod(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { //包装request, response ServletWebRequest webRequest = new ServletWebRequest(request, response); //获取DataBinderFactory WebDataBinderFactory binderFactory = getDataBinderFactory(handlerMethod); //获取模型属性工厂 ModelFactory modelFactory = getModelFactory(handlerMethod, binderFactory); //创建请求处理handlerMethod ServletInvocableHandlerMethod requestMappingMethod = createRequestMappingMethod(handlerMethod, binderFactory); //创建视图模型容器 ModelAndViewContainer mavContainer = new ModelAndViewContainer(); mavContainer.addAllAttributes(RequestContextUtils.getInputFlashMap(request)); modelFactory.initModel(webRequest, mavContainer, requestMappingMethod); mavContainer.setIgnoreDefaultModelOnRedirect(ignoreDefaultModelOnRedirect); //异步请求处理 AsyncWebRequest asyncWebRequest = WebAsyncUtils.createAsyncWebRequest(request, response); asyncWebRequest.setTimeout(asyncRequestTimeout); WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); asyncManager.setTaskExecutor(taskExecutor); asyncManager.setAsyncWebRequest(asyncWebRequest); asyncManager.registerCallableInterceptors(callableInterceptors); asyncManager.registerDeferredResultInterceptors(deferredResultInterceptors); if(asyncManager.hasConcurrentResult()) { Object result = asyncManager.getConcurrentResult(); mavContainer = (ModelAndViewContainer)asyncManager.getConcurrentResultContext()[0]; asyncManager.clearConcurrentResult(); if(logger.isDebugEnabled()) logger.debug((new StringBuilder()).append("Found concurrent result value [").append(result).append("]").toString()); requestMappingMethod = requestMappingMethod.wrapConcurrentResult(result); } //关键在这,处理请求 requestMappingMethod.invokeAndHandle(webRequest, mavContainer, new Object[0]); if(asyncManager.isConcurrentHandlingStarted()) return null; else //返回视图 return getModelAndView(mavContainer, modelFactory, webRequest); } //配置HandlerMethod上下文 private ServletInvocableHandlerMethod createRequestMappingMethod(HandlerMethod handlerMethod, WebDataBinderFactory binderFactory) { ServletInvocableHandlerMethod requestMethod = new ServletInvocableHandlerMethod(handlerMethod); requestMethod.setHandlerMethodArgumentResolvers(argumentResolvers); requestMethod.setHandlerMethodReturnValueHandlers(returnValueHandlers); requestMethod.setDataBinderFactory(binderFactory); requestMethod.setParameterNameDiscoverer(parameterNameDiscoverer); return requestMethod; } //渲染组装视图 private ModelAndView getModelAndView(ModelAndViewContainer mavContainer, ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception { modelFactory.updateModel(webRequest, mavContainer); if(mavContainer.isRequestHandled()) return null; ModelMap model = mavContainer.getModel(); ModelAndView mav = new ModelAndView(mavContainer.getViewName(), model); if(!mavContainer.isViewReference()) mav.setView((View)mavContainer.getView()); if(model instanceof RedirectAttributes) { Map flashAttributes = ((RedirectAttributes)model).getFlashAttributes(); HttpServletRequest request = (HttpServletRequest)webRequest.getNativeRequest(javax/servlet/http/HttpServletRequest); RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes); } return mav; } } public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { public final transient void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer mavContainer, Object providedArgs[]) throws Exception { Object returnValue = invokeForRequest(webRequest, mavContainer, providedArgs); setResponseStatus(webRequest); if(returnValue == null) { if(isRequestNotModified(webRequest) || hasResponseStatus() || mavContainer.isRequestHandled()) { mavContainer.setRequestHandled(true); return; } } else if(StringUtils.hasText(responseReason)) { mavContainer.setRequestHandled(true); return; } mavContainer.setRequestHandled(false); try { returnValueHandlers.handleReturnValue(returnValue, getReturnValueType(returnValue), mavContainer, webRequest); } } private HttpStatus responseStatus; private String responseReason; private HandlerMethodReturnValueHandlerComposite returnValueHandlers; }
//InvocableHandlerMethod
public class InvocableHandlerMethod extends HandlerMethod { // public final transient Object invokeForRequest(NativeWebRequest request, ModelAndViewContainer mavContainer, Object providedArgs[]) throws Exception { //获取方法参数 Object args[] = getMethodArgumentValues(request, mavContainer, providedArgs); if(logger.isTraceEnabled()) { StringBuilder sb = new StringBuilder("Invoking ["); sb.append(getBeanType().getSimpleName()).append("."); sb.append(getMethod().getName()).append("] method with arguments "); sb.append(Arrays.asList(args)); logger.trace(sb.toString()); } //invoke处理请求对应的Controller的Method.invoke() Object returnValue = invoke(args); if(logger.isTraceEnabled()) logger.trace((new StringBuilder()).append("Method [").append(getMethod().getName()).append("] returned [").append(returnValue).append("]").toString()); return returnValue; } //获取方法参数 private transient Object[] getMethodArgumentValues(NativeWebRequest request, ModelAndViewContainer mavContainer, Object providedArgs[]) throws Exception { MethodParameter parameters[] = getMethodParameters(); Object args[] = new Object[parameters.length]; for(int i = 0; i < parameters.length; i++) { MethodParameter parameter = parameters[i]; parameter.initParameterNameDiscovery(parameterNameDiscoverer); GenericTypeResolver.resolveParameterType(parameter, getBean().getClass()); args[i] = resolveProvidedArgument(parameter, providedArgs); if(args[i] != null) continue; if(argumentResolvers.supportsParameter(parameter)) try { args[i] = argumentResolvers.resolveArgument(parameter, mavContainer, request, dataBinderFactory); continue; } } return args; } // private transient Object invoke(Object args[]) throws Exception { //获取权限 ReflectionUtils.makeAccessible(getBridgedMethod()); //触发处理方法,返回结果 return getBridgedMethod().invoke(getBean(), args); } private WebDataBinderFactory dataBinderFactory; private HandlerMethodArgumentResolverComposite argumentResolvers; private ParameterNameDiscoverer parameterNameDiscoverer; }
//HandlerMethod
public class HandlerMethod { private class ReturnValueMethodParameter extends HandlerMethodParameter { public Class getParameterType() { return returnValue == null ? super.getParameterType() : returnValue.getClass(); } private final Object returnValue; final HandlerMethod this$0; public ReturnValueMethodParameter(Object returnValue) { this$0 = HandlerMethod.this; super(-1); this.returnValue = returnValue; } } private class HandlerMethodParameter extends MethodParameter { public Class getContainingClass() { return getBeanType(); } public Annotation getMethodAnnotation(Class annotationType) { return HandlerMethod.this.getMethodAnnotation(annotationType); } final HandlerMethod this$0; public HandlerMethodParameter(int index) { this$0 = HandlerMethod.this; super(bridgedMethod, index); } } public HandlerMethod(Object bean, Method method) { this.bean = bean; beanFactory = null; this.method = method; bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); parameters = initMethodParameters(); } public transient HandlerMethod(Object bean, String methodName, Class parameterTypes[]) throws NoSuchMethodException { this.bean = bean; beanFactory = null; method = bean.getClass().getMethod(methodName, parameterTypes); bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); parameters = initMethodParameters(); } public HandlerMethod(String beanName, BeanFactory beanFactory, Method method) { bean = beanName; this.beanFactory = beanFactory; this.method = method; bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); parameters = initMethodParameters(); } private HandlerMethod(HandlerMethod handlerMethod, Object handler) { bean = handler; beanFactory = handlerMethod.beanFactory; method = handlerMethod.method; bridgedMethod = handlerMethod.bridgedMethod; parameters = handlerMethod.parameters; } //获取处理bean-Conroller public Object getBean() { return bean; } //获取处理方法 protected Method getBridgedMethod() { return bridgedMethod; } //获取方法参数 public MethodParameter[] getMethodParameters() { return parameters; } protected final Log logger; private final Object bean; private final BeanFactory beanFactory; private final Method method; private final Method bridgedMethod; private final MethodParameter parameters[]; }
//MethodParameter
public class MethodParameter { public MethodParameter(Method method, int parameterIndex) { this(method, parameterIndex, 1); } public MethodParameter(Method method, int parameterIndex, int nestingLevel) { this.nestingLevel = 1; Assert.notNull(method, "Method must not be null"); this.method = method; this.parameterIndex = parameterIndex; this.nestingLevel = nestingLevel; constructor = null; } public MethodParameter(Constructor constructor, int parameterIndex) { this(constructor, parameterIndex, 1); } public MethodParameter(Constructor constructor, int parameterIndex, int nestingLevel) { this.nestingLevel = 1; Assert.notNull(constructor, "Constructor must not be null"); this.constructor = constructor; this.parameterIndex = parameterIndex; this.nestingLevel = nestingLevel; method = null; } private final Method method; private final Constructor constructor; private final int parameterIndex; private Class containingClass; private Class parameterType; private Type genericParameterType; private Annotation parameterAnnotations[]; private ParameterNameDiscoverer parameterNameDiscoverer; private String parameterName; private int nestingLevel; Map typeIndexesPerLevel; }
总结:
从上面我们可以看出,RequestMappingHandlerAdapter主要是解决请求的,会话,请求头部处理,数据的绑定等,然后从容器中,获取handlerMethod,处理业务逻辑,获取数据,并渲染视图,返回。
发表评论
-
Spring的RequestMappingHandlerMapping详解
2016-09-23 08:40 4591深刻理解IdentityHashMap:http://dona ... -
Spring+Mybatis多数据源的实现
2016-09-21 18:15 3094浅谈Spring事务隔离级别:http://www.cnblo ... -
Spring的DefaultAnnotationHandlerMapping详解
2016-09-20 08:47 5840前面我们讲解过Dispatcher ... -
Spring-DispatcherServlet请求处理
2016-09-19 15:42 1685Spring-DispatcherServlet初始化详解:h ... -
Spring-DispatcherServlet初始化详解
2016-09-19 15:03 3690Spring-DispatcherServlet请求处理:ht ... -
Spring上下文加载监听器ContextLoaderListener--源码解析
2016-09-18 18:10 4656一般在web应用配置Spring上下文如下,那么Context ... -
JobDetailFactoryBean与MethodInvokingJobDetailFactoryBean源码分析
2016-09-13 16:07 4296Spring与Quartz集成详解:http://donald ... -
Spring与Quartz集成-源码分析
2016-09-13 11:50 2712在阅读以下文章之前,如果对Quartz任务调度不是很熟悉,请看 ... -
Spring与Quartz集成详解
2016-09-09 17:52 2816首先这个所有的依赖包就不需要多讲了,首先下载Quazrt发布包 ... -
Spring,ApplicationContextAware的作用
2016-08-24 17:38 7引用:http://blog.csdn.net/kaiwii/ ... -
Spring Interceptor
2016-05-31 17:12 570Spring Interceptor相关知识:http://h ... -
基于注解的Spring AOP
2016-05-31 16:05 921Spring AOP 基本概念:http://hotstron ... -
Spring的Task定时器
2016-05-31 10:34 7061.开启注解,定义扫描包 <mvc:annotation ...
相关推荐
1. org.springframework.web.servlet.DispatcherServlet:这是 Spring MVC 的入口点,源码中可以看到它如何初始化 MVC 配置,并进行请求调度。 2. org.springframework.web.servlet.mvc.method.annotation....
最后,应用的启动入口通常是一个Servlet或Filter,例如Spring的ContextLoaderListener或DelegatingFilterProxy,它们负责初始化Spring容器,并在Web应用启动时加载配置。 总结起来,整合Spring、SpringMVC和MyBatis...
8. **FrameworkServlet**:`DispatcherServlet`的父类,提供了一些基本的HTTP请求处理功能,如初始化、销毁、处理请求等。 9. **HiddenHttpMethodFilter**:隐藏的HTTP方法过滤器,用于处理PUT、DELETE等非GET/POST...
- 对于Spring MVC的初始化,通常还需要一个`ContextLoaderListener`来加载Spring的ApplicationContext,以及一个`DispatcherServlet`来处理请求。 - 在`DispatcherServlet`配置中,可以指定Spring MVC的配置文件,...
上述配置指定了DispatcherServlet的初始化参数`contextConfigLocation`,用于指定Spring MVC的配置文件`spring-mvc.xml`的位置。 ### 3. `spring-mvc.xml`配置 在`spring-mvc.xml`中,我们将定义处理器映射器、...
- 初始化上下文定义(如文件上传解析器、国际化资源文件等)。 - 接收并响应客户端请求。 2. **HandlerMapping**:负责根据请求找到合适的控制器(Handler)。 - 常见的有 `BeanNameUrlHandlerMapping`、`...
- **DispatcherServlet**的初始化过程,包括配置加载、初始化处理器映射器和适配器等。 - **HandlerMapping**的实现,如BeanNameUrlHandlerMapping、SimpleUrlHandlerMapping等,以及自定义映射策略。 - **...
`web.xml` 中配置的 `DispatcherServlet` 初始化参数和拦截器链会影响其行为。 5. **处理器映射器(HandlerMapping)**:处理器映射器负责将请求URL映射到合适的控制器方法。例如,`BeanNameUrlHandlerMapping` 和 ...
比如,`SimpleControllerHandlerAdapter`处理实现了`Controller`接口的类,而`RequestMappingHandlerAdapter`处理带有注解的方法。 4. **请求处理过程**: - 当一个HTTP请求到达时,`DispatcherServlet`会根据请求...
另外,还需要配置 ContextLoaderListener 以加载Spring的全局配置文件`applicationContext.xml`,该监听器会在Web应用启动时初始化Spring的ApplicationContext: ```xml <!-- Spring 配置 --> <listener-class>...
Spring MVC为不同类型的Handler提供了不同的HandlerAdapter,比如HttpRequestHandlerAdapter、SimpleControllerHandlerAdapter以及用于处理@RequestMapping注解的RequestMappingHandlerAdapter。 当Handler处理请求...
Bean 定义、初始化、配置和管理都在这里完成。 5. **spring-expression.jar (SPeL)**:Spring 表达式语言提供了一种强大的方式来在运行时查询和操作对象图。在 Spring MVC 中,它常用于模型绑定和数据验证时的条件...
### Spring RequestMappingHandlerMapping详解 #### 一、前言 `...此外,与`HandlerAdapter`、`HandlerInterceptor`等组件的紧密结合,也使得Spring MVC框架能够在处理复杂的Web请求时表现出色。
定义servlet并指定它的初始化参数,如上下文配置文件的位置。 ```xml <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-...
创建 `web.xml` 文件作为项目的部署描述符,配置 DispatcherServlet 作为请求的前端控制器,以及 SpringMVC 的初始化参数: ```xml <servlet-name>dispatcher</servlet-name> <servlet-class>org.spring...
同时,还要配置ContextLoaderListener,用于初始化Spring的全局ApplicationContext。 接着,创建SpringMVC的配置文件,比如`applicationContext-mvc.xml`,在这里可以定义Bean、数据源、视图解析器、拦截器等。例如...
1. **web.xml配置**: 配置DispatcherServlet,定义初始化参数和映射URL。 ```xml <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> ...
例如,定义了 DispatcherServlet 的初始化参数,以及映射路径,如 `<url-pattern>/</url-pattern>` 表示所有请求都将由 DispatcherServlet 处理。 2. **spring-servlet.xml**:这是 Spring MVC 的配置文件,通常...
2. 配置web.xml:这是SpringMVC的初始化配置文件,需要定义DispatcherServlet,并指定其配置文件路径: ```xml <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet....