SpringBoot特点
依赖管理
依赖管理
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
<relativePath/>
</parent>
他的父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.6</version>
<relativePath/>
</parent>
几乎声明了所有开发中常用的依赖的版本号,自动版本仲裁机制
1.见到很多spring-boot-starter-*,*就代表某种场景
2.这个场景的所有的常规需要的依赖我们都会自动引入
3.Springboot所有能支持的场景https://docs.spring.io/spring-boot/docs/current/reference/html/using.html#using.build-systems.starters
4.见到的*-spring-boot-starter,第三方提供的
5.所有场景启动器最底层的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.5.6</version>
<scope>compile</scope>
</dependency>
引入依赖默认都可以不写版本
引入非版本仲裁的jar,要写版本
查看spring-boot-dependencies里面规定当前依赖的版本用的key
在当前项目里重写配置
<properties>
<mysql.version>8.0.27</mysql.version>
</properties>
自动配置
引入Tomcat
配置Tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.5.6</version>
<scope>compile</scope>
</dependency>
引入SpringMVC全套组件
自动配号SpringMVC常用组件(功能)
SpringBoot帮我们配置好了所有web开发的常见问题
主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
无需以前的包扫描
想要改变包的扫描路径,@SpringBootApplication(scanBasePackages = "com.zjc")
或者@ComponentScan指定扫描
@SpringBootApplication
等同于
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan("com.zjc")
默认配置最终都是映射到一个Properties上
配置文件的值最终会绑定每个类上,这个类会在容器中创建对象
非常多的starter
引入哪些场景的自动配置才会开启
SpringBoot所有的自动配置功能都在spring-boot-autoconfigure包