springboot原理初探

1. 父项目

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.0.RELEASE</version>
    </parent>

	它的父项目是

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.1.0.RELEASE</version>
        <relativePath>../../spring-boot-dependencies</relativePath>
    </parent>
	这个父项目管理所有依赖的版本,被称为spring boot版本仲裁中心
	以后导依赖默认使用这里的版本,不需要自己写,没有的才需要自己写版本

2. starter 启动器

starter 是为满足某一场景的一系列依赖集合

官方介绍

Starters are a set of convenient dependency descriptors that you can include in your application. You get a one-stop shop for all the Spring and related technologies that you need without having to hunt through sample code and copy-paste loads of dependency descriptors. For example, if you want to get started using Spring and JPA for database access, include the spring-boot-starter-data-jpa dependency in your project.

The starters contain a lot of the dependencies that you need to get a project up and running quickly and with a consistent, supported set of managed transitive dependencies.

3. Spring Boot入口程序

@SpringBootApplication
public class HelloworldMain {
    public static void main(String[] args) {
        SpringApplication.run(HelloworldMain.class, args);
    }
}

@SpringBootApplication

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration // 注解标注这是一个spring boot配置类
@EnableAutoConfiguration // 开启自动配置功能
@ComponentScan(
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication {

@SpringBootConfiguration 注解标注这是一个spring boot配置类

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
}

@EnableAutoConfiguration

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
// 将被注解类所在包及子包下的组件扫描到spring容器,相当于以前spring里面的注解配置类
@AutoConfigurationPackage 
// 完成功能的自动配置,如以前要自己做的spring mvc配置
@Import({AutoConfigurationImportSelector.class}) 
public @interface EnableAutoConfiguration {

猜你喜欢

转载自blog.csdn.net/u013738122/article/details/83820668