zoukankan      html  css  js  c++  java
  • SpringMvc源码入门

    private void initHandlerMappings(ApplicationContext context) {
            this.handlerMappings = null;
            if (this.detectAllHandlerMappings) {
                Map<String, HandlerMapping> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerMapping.class, true, false);
                if (!matchingBeans.isEmpty()) {
                    this.handlerMappings = new ArrayList(matchingBeans.values());
                    AnnotationAwareOrderComparator.sort(this.handlerMappings);
                }
            } else {
                try {
                    HandlerMapping hm = (HandlerMapping)context.getBean("handlerMapping", HandlerMapping.class);
                    this.handlerMappings = Collections.singletonList(hm);
                } catch (NoSuchBeanDefinitionException var3) {
                }
            }
    
            if (this.handlerMappings == null) {
                this.handlerMappings = this.getDefaultStrategies(context, HandlerMapping.class);
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("No HandlerMappings found in servlet '" + this.getServletName() + "': using default");
                }
            }
    
        }
    
        private void initHandlerAdapters(ApplicationContext context) {
            this.handlerAdapters = null;
            if (this.detectAllHandlerAdapters) {
                Map<String, HandlerAdapter> matchingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerAdapter.class, true, false);
                if (!matchingBeans.isEmpty()) {
                    this.handlerAdapters = new ArrayList(matchingBeans.values());
                    AnnotationAwareOrderComparator.sort(this.handlerAdapters);
                }
            } else {
                try {
                    HandlerAdapter ha = (HandlerAdapter)context.getBean("handlerAdapter", HandlerAdapter.class);
                    this.handlerAdapters = Collections.singletonList(ha);
                } catch (NoSuchBeanDefinitionException var3) {
                }
            }
    
            if (this.handlerAdapters == null) {
                this.handlerAdapters = this.getDefaultStrategies(context, HandlerAdapter.class);
                if (this.logger.isDebugEnabled()) {
                    this.logger.debug("No HandlerAdapters found in servlet '" + this.getServletName() + "': using default");
                }
            }
    
        }
    private void initHandlerMappings(ApplicationContext context) {
                    //主要工作是给这个属性赋值
            this.handlerMappings = null;
    
            if (this.detectAllHandlerMappings) {
                // Find all HandlerMappings in the ApplicationContext, including ancestor contexts.
                //取得IoC容器中所有HandlerMapping类型的Bean
                Map<String, HandlerMapping> matchingBeans =
                        BeanFactoryUtils.beansOfTypeIncludingAncestors(context, HandlerMapping.class, true, false);
                if (!matchingBeans.isEmpty()) {
                    this.handlerMappings = new ArrayList<HandlerMapping>(matchingBeans.values());
                    // We keep HandlerMappings in sorted order.
                    //注意排序
                    OrderComparator.sort(this.handlerMappings);
                }
            }
            else {
                try {
                    HandlerMapping hm = context.getBean(HANDLER_MAPPING_BEAN_NAME, HandlerMapping.class);
                    this.handlerMappings = Collections.singletonList(hm);
                }
                catch (NoSuchBeanDefinitionException ex) {
                    // Ignore, we'll add a default HandlerMapping later.
                }
            }
    
            // Ensure we have at least one HandlerMapping, by registering
            // a default HandlerMapping if no other mappings are found.
            if (this.handlerMappings == null) {
                this.handlerMappings = getDefaultStrategies(context, HandlerMapping.class);
                if (logger.isDebugEnabled()) {
                    logger.debug("No HandlerMappings found in servlet '" + getServletName() + "': using default");
                }
            }
        }
    protected void initStrategies(ApplicationContext context) {
        // 文件上传解析器
        initMultipartResolver(context);
        // 本地化解析器
        initLocaleResolver(context);
        // 主题解析器
        initThemeResolver(context);
        // 处理器映射器(url和Controller方法的映射)
        initHandlerMappings(context);
        // 处理器适配器(实际执行Controller方法)
        initHandlerAdapters(context);
        // 处理器异常解析器
        initHandlerExceptionResolvers(context);
        // RequestToViewName解析器
        initRequestToViewNameTranslator(context);
        // 视图解析器(视图的匹配和渲染)
        initViewResolvers(context);
        // FlashMap管理者
        initFlashMapManager(context);
    }
  • 相关阅读:
    Unity3D鼠标点击处
    Unity3D静态AI自动寻路
    Unity3D 雷达检测器
    Unity3D重新加载光线变暗问题
    Unity3D切换场景不销毁物体
    软件&环境&网页
    2020软件工程作业05
    2020软件工程作业04
    利用Java输入输出流更改文件中指定的内容
    2020软件工程作业03
  • 原文地址:https://www.cnblogs.com/longxok/p/11413165.html
Copyright © 2011-2022 走看看