springmvc源碼解析之@EnableWebMvc三

說在前面web

本次主要介紹springmvc配置解析。關注「天河聊架構」更多精彩。spring

 

springmvc配置解析架構

@EnableWebMvc這個註解幹了什麼,初始化defaultServletHandlerMappingmvc

 

進入到這個方法org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#defaultServletHandlerMappingapp

@Bean
   public HandlerMapping defaultServletHandlerMapping() {
//    建立DefaultServletHandlerConfigurer
      DefaultServletHandlerConfigurer configurer = new DefaultServletHandlerConfigurer(this.servletContext);
//    配置DefaultServletHandlerConfigurer -》
      configureDefaultServletHandling(configurer);
//    構建HandlerMapping -》
      HandlerMapping handlerMapping = configurer.buildHandlerMapping();
      return (handlerMapping != null ? handlerMapping : new EmptyHandlerMapping());
   }

進入到這個方法org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration#configureDefaultServletHandlingide

@Override
protected void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
   this.configurers.configureDefaultServletHandling(configurer);
}

往上返回到這個方法org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer#buildHandlerMappingui

protected SimpleUrlHandlerMapping buildHandlerMapping() {
      if (this.handler == null) {
         return null;
      }

//    建立SimpleUrlHandlerMapping
      SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
      handlerMapping.setUrlMap(Collections.singletonMap("/**", this.handler));
      handlerMapping.setOrder(Integer.MAX_VALUE);
      return handlerMapping;
   }

往上返回到這個方法org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport#defaultServletHandlerMappingthis

 

 

說到最後源碼

本次源碼解析僅表明我的觀點,僅供參考。servlet

相關文章
相關標籤/搜索