原理初探
自动装配:
pom.xml
- 我们呢去创建的Springboot项目呢其实是一个做项目它呢是有父项目存在的在父项目中有它需要的核心依赖!
- spring-boot-dependencies:核心依赖这个呢在父工程中大家可以点进去查看
- 我们在写或者引入一些Springboot依赖的时候,不需要去指定版本,就是因为在父项目中有这些版本仓库
启动器
<!--相当于一个启动器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
- 启动器:这个东西其实就是一个SpringBoot的一个启动场景;
- 比如spring-boot-starter-web,他就会帮我们自动导入web环境所有依赖!
- springboot会将所有的场景功能,都变成一个个的启动器
- 我们使用什么功能,就只需要找到对应的启动器就可以了starter这个呢在官方文档中都有
主程序
package com.cloud;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
//本身就是Spring的一个组件
//程序的主入口
//@SpringBootApplication标注这个类是一个springboot的应用
@SpringBootApplication
public class Springboot01HelloworldApplication {
public static void main(String[] args) {
//SpringApplication
//就springboot应用启动
SpringApplication.run(Springboot01HelloworldApplication.class, args);
}
}
注解:
@SpringBootConfiguration:spring的配置
@Configuration:spring配置类
@Component:说明这也是个spring组件
@EnableAutoConfiguration:自动配置
@AutoConfigurationPackage:自动装配包
@Improt(AutoConfigurationPackages.Registrar.class):自动装配包注册
@Import(AutoConfigurationImportSelector.class):自动配置导入选择
//获取所有的配置
- 关于SpringBoot,谈谈你的理解:
自动装配
run()方法
全面接管SpringMVC的配置!
- 自动装配在理解