SpringBoot的特点
1 依赖管理
①父项目做依赖管理
②自动版本仲裁机制
③引入场景启动器
2 默认的包结构
主程序所在的包及其下面的子包里面的组件都会被默认扫描进来,无需包扫描配置
3 注解含义
@configuration 告诉SpringBoot这是一个配置类,
@Import给容器中自动创建出这两个类型的组件,默认组件的名字就是全类名
@Conditional 满足Conditional指定的条件,则进行组件注入
4 配置文件yaml简介
yaml是“UAML Aint Markup Language ”的递归缩写,是一种标记语言,非常适合做数据为中心的配置文件
基本语法
key:value k v 之间有空格
大小写敏感
使用缩进表示层级关系
缩进不允许使用Tab键,只允许使用空格
缩进的空格数不重要,只要层级相同的元素左对齐即可
# 表示注释
字符串不需要加引号,
通过创建Spring Initializer 来创建第一个web项目,
一路next下去发现会创建失败,有些文件不能下载成功,
为了解决这个问题,网上找了一些办法顺利解决,
选中custom项目,并且输入下面的网址,然后一路next就可以创建成功了
项目创建成功后,准备尝试编写代码,学习web开发,但是发现一个问题,就是application.properties文件的前边没有springboot的标记,而且主程序也没有springboot的标记,同时主程序右键没有run选项,后来又重新创建了一下这个程序,发现了问题,主要是在程序创建的时候很多东西没有下载完,所以下次创建的时候,一定注意idea右下角的滚动条,要把所有的资源下载和加载完毕,创建完成的状态应该是这样的
很多时候我们都会发现主程序没有run选项,无法启动,可能会想到有什么东西没有设置,这种想法是正常的,但是也有一种情况是我遇到的这种,就是很多资源没有加载下载完毕,或者下载失败,程序没有完全创建成功。
SpringMVC自动配置概览
Spring Boot provides auto - configuration for Spring MVC that works well with most
applications ( 大多场景我们都无需自定义配置 )
The auto - configuration adds the following features on top of Spring ’ s defaults :
• Inclusion of ContentNegotiatingViewResolver and BeanNameViewResolver beans .
°
内容协商视图解析器和 BeanName 视图解析器
• Support for serving static resources , including support for WebJars ( covered later in this
document < https : // docs . spring . io / spring - boot / docs / current / reference / html / spring - boot -
features . html # boot - features - spring - mvc - static - content > ) ) .
°
静态资源 ( 包括 webjars )
• Automatic registration of Converter , GenericConverter , and Formatter beans .
°
自动注册 Converter , GenericConverter , Formatter
• Support for HttpMessageConverters ( covered later in this document
< https : // docs . spring . io / spring - boot / docs / current / reference / html / spring - boot -
features . html # boot - features - spring - mvc - message - converters > ) .
。
支持 HttpMessageConverters ( 后来我们配合内容协商理解原理 )
• Automatic registration of MessageCodesResolver ( covered later in this document
https : / / docs . spring . io / spring - boot / docs / current / reference / html / spring - boot -
features . html # boot - features - spring - message - codes > ) .
。
自动注册 MessageCodesResolver ( 国际化用 )
• Static index . html support .
青争态 index . html 页支持
• Custom Favicon support ( covered later in this document < https : / / docs . spring . io / spring -
boot / docs / current / reference / html / spring - boot - features . html # boot - features - spring - mvc -
favicon > ) .
o
自定义
• Automatic use of a ConfigurableWebBindinglnitializer bean ( covered later in this
document < https : // docs . spring . io / spring - boot / docs / current / reference / html / spring - boot -
features . html # boot - features - spring - mvc - web - binding - initializer > )
2022年8月14日于苏州