zoukankan      html  css  js  c++  java
  • Spring mvc 启动 和 请求分发

    Spring mvc 启动 和 请求分发
    启动加载:
        abstract class HttpServletBean extends HttpServlet
        void init() 
        initServletBean();
    
            abstract class FrameworkServlet extends HttpServletBean
            void initServletBean()
            WebApplicationContext initWebApplicationContext()
            onRefresh(wac);
            
                class DispatcherServlet extends FrameworkServlet
                void onRefresh(ApplicationContext context)
                void initStrategies(ApplicationContext context)
                
                initMultipartResolver(context);
                initLocaleResolver(context);
                initThemeResolver(context);
                initHandlerMappings(context);
                initHandlerAdapters(context);
                initHandlerExceptionResolvers(context);
                initRequestToViewNameTranslator(context);
                initViewResolvers(context);
                initFlashMapManager(context);
            
        
        
    请求分发:     
          HTTP request-->httpServlet  
            --->class FrameworkServlet ---->doPost() or doGet()
          
            processRequest(HttpServletRequest request, HttpServletResponse response)
            doService(request, response);
            
               class DispatcherServlet extends FrameworkServlet
               void doService(HttpServletRequest request, HttpServletResponse response)
               doDispatch(request, response);
                      
               // Actually invoke the handler.
                mv = ha.handle(processedRequest, response, mappedHandler.getHandler());
                
                 SimpleControllerHandlerAdapter implements HandlerAdapter
                 
                 ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
                       ((Controller) handler).handleRequest(request, response);
                       
                    用户在使用时,实现了 AbstractController.handleRequestInternal()
                    或者    重写 Controller handleRequest()             
                       
                          
                 
                 
                 ha 使用哪个Adapter ? 一般需要在配置文件中写明 
                 <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
                 <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
                 
                 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>  
                 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
                 
                 下面这个文件中会自动加载
                 /org/springframework/web/servlet/DispatcherServlet.properties
    
        
        org.springframework.web.servlet.HandlerMapping=org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,
        org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping
    
        org.springframework.web.servlet.HandlerAdapter=org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,
        org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,
        org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
        
        
        
        
        
        
        
        
        
        
  • 相关阅读:
    Java [Leetcode 319]Bulb Switcher
    Java [Leetcode 122]Best Time to Buy and Sell Stock II
    谱聚类算法
    Java [Leetcode 238]Product of Array Except Self
    Java [Leetcode 260]Single Number III
    X++ StrFix方法
    D365 FO第三方访问https证书问题
    D365 FO 使用.NET DLL
    D365 FO第三方集成(四)---客户端调用
    D365 FO第三方集成(三)---服务实现
  • 原文地址:https://www.cnblogs.com/rojas/p/6951771.html
Copyright © 2011-2022 走看看