spring boot框架学习5-spring boot的web
本章节主要内容:
通过前面的学习,我们了解并快速完成了spring boot第一个应用。spring boot企业级框架,那么spring boot怎么读取静态资源?如js文件夹,css文件以及png/jpg图片呢?怎么自定义消息转换器呢?怎么自定义spring mvc的配置呢?这些我们在公司都需要用的。这些怎么解决呢?在接下来的小节详细讲解这些。好了,现在开启spring boot的web开发第一节
本节主要:
1:spring boot 自动配置viewResolver
本文是《凯哥陪你学系列-框架学习之spring boot框架学习》中第五篇 spring boot框架学习5-spring boot的web开发(1)
声明:本文系凯哥Java(www.kaigejava.com)原创,未经允许,禁止转载!
一:spring boot自动配置viewResolver讲解
1.1:spring boot所有自动配置在哪个包下?
所有的配置都在spring-boot-autoconfigure这个包下。如下图:

1.2 spring bootviewResolver具体位置:

具体:org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
源码大致讲解:

1:@conditionalOnClass:条件选择注解
源码:

源码注释大致意思:只有value中配置的类在当前的classpath下才可以。
所以:
@ConditionalOnClass({ Servlet.class, DispatcherServlet.class,
WebMvcConfigurerAdapter.class })含义:
当前项目必须含有Servlet、DispatcherServlet、WebMvcConfigurerAdapter三个条件同时存在,webMvcAutoConfiguration才起作用。
2:@ConditionalOnMissingBean:如果没有就创建一个。
源码注释:
如下图含义:
当没有request的过滤器时候创建一个。

请点击此处输入图片描述

3:查看WebMvcAutoConfiguration源码我们熟悉的其他
3.1:资源添加处理的handlers:

3.2校验validator相关的

3.3欢迎页面相关的:

源码讲解,相对来说是比较慢的,所以本节想讲解到这里。在接下来将讲解一个重点InternalResourceViewResolver以及读取静态资源文件。欢迎大家继续学习。
本系列其他文章:
spring boot框架学习学前掌握之重要注解(1)-spring的java配置方式
spring boot框架学习学前掌握之重要注解(2)-通过java的配置方式进行配置spring
spring boot框架学习学前掌握之重要注解(3)-通过注解方式读取外部资源配置文件
spring boot框架学习学前掌握之重要注解(4)-通过注解方式读取外部资源配置文件2
spring boot框架学习1-认识spring boot和快速入门
spring boot框架学习2-spring boot核心(1)
spring boot框架学习3-spring boot核心(2)
spring boot框架学习5-spring boot的web开发(1)
欢迎关注凯哥公众号:凯哥Java
欢迎访问凯哥个人网站:www.kaigejava.com
本文出处:http://www.kaigejava.com/article/detail/53
spring boot系列教程:http://kaigejava.com/article/list?cateid=3