springboot的springMVC配置,源码

1,前端控制器自动管理

springboot的springMVC配置,源码_第1张图片

 

 

 DispatcherServletAutoConfiguration 中

此方法创建了前端控制器

springboot的springMVC配置,源码_第2张图片

 

 

注册了前端控制器

 

 

 

springboot的springMVC配置,源码_第3张图片

 

 其中标黄色一行最后的  .getPath()方法点进去

springboot的springMVC配置,源码_第4张图片

 

 

 String path = "/" 默认,所以这就是后缀不用加.do或者其他后缀的原因

 

2,控制器的自动管理

自动扫描,目录为启动类的包,或者子包

或者使用@ComponentScan去处理,自定义扫描路径

 

3,视图解析器的自动管理

 

 
  
@Bean
@ConditionalOnMissingBean
public InternalResourceViewResolver defaultViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix(this.mvcProperties.getView().getPrefix());
resolver.setSuffix(this.mvcProperties.getView().getSuffix());
return resolver;
}

@Bean
@ConditionalOnBean(View.class)
@ConditionalOnMissingBean
public BeanNameViewResolver beanNameViewResolver() {
BeanNameViewResolver resolver = new BeanNameViewResolver();
resolver.setOrder(Ordered.LOWEST_PRECEDENCE - 10);
return resolver;
}

@Bean
@ConditionalOnBean(ViewResolver.class)
@ConditionalOnMissingBean(name = "viewResolver", value = ContentNegotiatingViewResolver.class)
public ContentNegotiatingViewResolver viewResolver(BeanFactory beanFactory) {
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(beanFactory.getBean(ContentNegotiationManager.class));
// ContentNegotiatingViewResolver uses all the other view resolvers to locate
// a view so it should have a high precedence
resolver.setOrder(Ordered.HIGHEST_PRECEDENCE);
return resolver;
}
 

 

文件上传下载的视图解析器

MultipartAutoConfiguration 类

你可能感兴趣的:(springboot的springMVC配置,源码)