核心依赖在父工程中:spring-boot-starter-parent—>spring-boot-dependencies.xml
资源导出设置:spring-boot-starter-parent.xml
插件设置:spring-boot-starter-parent.xml,若下载失败需要重新maven/install下
springboot是通过main方法下的SpringApplication.run方法启动的,启动的时候他会调用refshContext方法,先刷新容器,然后根据解析注解或者解析配置文件的形式注册bean,而它是通过启动类的SpringBootApplication注解进行开始解析的,他会根据EnableAutoConfiguration开启自动化配置,里面有个核心方法ImportSelect选择性的导入,根据loadFanctoryNames根据classpash路径以MATA-INF/spring.factorces下面以xxxEnableAutoConfiguration开头的key去加载里面所有对应的自动化配置,他并不是把这一百二十多个自动化配置全部导入,在他每个自动化配置里面都有条件判断注解,先判断是否引入相互的jar包,再判断容器是否有bean再进行注入到bean容器
传统的 Spring 项目想要运行,不仅需要导入各种依赖,还要对各种 XML 配置文件进行配置,十分繁琐,但 Spring Boot 项目在创建完成后,即使不编写任何代码,不进行任何配置也能够直接运行,这都要归功于 Spring Boot 的 starter 机制
Spring Boot 将日常企业应用研发中的各种场景都抽取出来,做成一个个的 starter(启动器),starter中整合了该场景下各种可能用到的依赖,用户只需要在Maven中引入starter依赖,SpringBoot就能自动扫描到要加载的信息并启动相应的默认配置。starter提供了大量的自动配置,让用户摆脱了处理各种依赖和配置的困扰。所有这些 starter都遵循着约定成俗的默认配置,并允许用户调整这些配置,即遵循“约定大于配置”的原则。即Springboot的启动场景;
在引入一些Springboot依赖的时候,不需要指定版本,就因为有上面dependencies这些版本仓库
并不是所有的 starter 都是由 Spring Boot 官方提供的,也有部分 starter 是第三方技术厂商提供的,例如 druid-spring-boot-starter和mybatis-spring-boot-starter 等等。当然也存在个别第三方技术,Spring Boot 官方没提供 starter,第三方技术厂商也没有提供 starter。
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.7.0
com.example
springbootdemo
0.0.1-SNAPSHOT
springbootdemo
Demo project for Spring Boot
12
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-mail
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-maven-plugin
[INFO] com.example:springbootdemo:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.7.0:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:2.7.0:compile
[INFO] | | \- org.springframework:spring-context:jar:5.3.20:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.7.0:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:2.7.0:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.2.11:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.2.11:compile
[INFO] | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile
[INFO] | | | \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] | | \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO] | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | +- org.springframework:spring-core:jar:5.3.20:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.3.20:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.30:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:2.7.0:compile
[INFO] | +- org.springframework:spring-context-support:jar:5.3.20:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.3.20:compile
[INFO] | \- com.sun.mail:jakarta.mail:jar:1.6.7:compile
[INFO] | \- com.sun.activation:jakarta.activation:jar:1.2.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.7.0:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:2.7.0:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.7.0:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.7.0:test
[INFO] | | +- net.minidev:json-smart:jar:2.4.8:test
[INFO] | | | \- net.minidev:accessors-smart:jar:2.4.8:test
[INFO] | | | \- org.ow2.asm:asm:jar:9.1:test
[INFO] | | \- org.slf4j:slf4j-api:jar:1.7.36:compile
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:test
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:1.2.2:test
[INFO] | +- org.assertj:assertj-core:jar:3.22.0:test
[INFO] | +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter:jar:5.8.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-api:jar:5.8.2:test
[INFO] | | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | | +- org.junit.platform:junit-platform-commons:jar:1.8.2:test
[INFO] | | | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-params:jar:5.8.2:test
[INFO] | | \- org.junit.jupiter:junit-jupiter-engine:jar:5.8.2:test
[INFO] | | \- org.junit.platform:junit-platform-engine:jar:1.8.2:test
[INFO] | +- org.mockito:mockito-core:jar:4.5.1:test
[INFO] | | +- net.bytebuddy:byte-buddy:jar:1.12.10:test
[INFO] | | +- net.bytebuddy:byte-buddy-agent:jar:1.12.10:test
[INFO] | | \- org.objenesis:objenesis:jar:3.2:test
[INFO] | +- org.mockito:mockito-junit-jupiter:jar:4.5.1:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] | | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] | +- org.springframework:spring-test:jar:5.3.20:test
[INFO] | \- org.xmlunit:xmlunit-core:jar:2.9.0:test
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:2.7.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-json:jar:2.7.0:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.13.3:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.13.3:compile
[INFO] | | \- com.fasterxml.jackson.core:jackson-core:jar:2.13.3:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.13.3:compile
[INFO] | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.13.3:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.13.3:compile
[INFO] +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.7.0:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.63:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.63:compile
[INFO] | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.63:compile
[INFO] +- org.springframework:spring-web:jar:5.3.20:compile
[INFO] \- org.springframework:spring-webmvc:jar:5.3.20:compile
[INFO] +- org.springframework:spring-aop:jar:5.3.20:compile
[INFO] \- org.springframework:spring-expression:jar:5.3.20:compile
这些版本信息是由 spring-boot-starter-parent(版本仲裁中心) 统一控制的。
Spring MVC是Spring提供的一个基于MVC设计模式的轻量级Web开发框架,其本身就是Spring框架的一部分,可以与Spring 无缝集成,性能方面具有先天的优越性,是当今业界最主流的 Web 开发框架之一。
Spring Boot 是在Spring的基础上创建一款开源框架,它提供了spring-boot-starter-web(Web 场景启动器)来为 Web 开发予以支持。spring-boot-starter-web为我们提供了嵌入的Servlet容器以及SpringMVC的依赖,并为Spring MVC提供了大量自动配置,可以适用于大多数 Web 开发场景。
Spring Boot 为 Spring MVC 提供了自动配置,并在 Spring MVC默认功能的基础上添加了以下特性:
只要我们在Spring Boot项目中的pom.xml中引入了 spring-boot-starter-web ,即使不进行任何配置,也可以直接使用Spring MVC 进行Web 开发。
org.springframework.boot
spring-boot-starter-parent
2.7.0
Spring Boot项目可以通过继承spring-boot-starter-parent来获得一些合理的默认配置,它主要提供了以下特性:
查看 spring-boot-starter- parent的底层代码,可以发现其有一个父级依赖 spring-boot-dependencies。
org.springframework.boot
spring-boot-dependencies
2.7.0
4.0.0
org.springframework.boot
spring-boot-dependencies
2.7.0
pom
spring-boot-dependencies
Spring Boot Dependencies
https://spring.io/projects/spring-boot
Apache License, Version 2.0
https://www.apache.org/licenses/LICENSE-2.0
Pivotal
info@pivotal.io
Pivotal Software, Inc.
https://www.spring.io
https://github.com/spring-projects/spring-boot
5.16.5
2.7.7
1.9.96
2.19.1
...
org.apache.activemq
activemq-amqp
${activemq.version}
org.apache.activemq
activemq-blueprint
${activemq.version}
org.apache.activemq
activemq-broker
${activemq.version}
...
org.codehaus.mojo
build-helper-maven-plugin
${build-helper-maven-plugin.version}
org.flywaydb
flyway-maven-plugin
${flyway.version}
...
以上配置中,部分元素说明如下:
dependencyManagement :负责管理依赖;
pluginManagement:负责管理插件;
properties:负责定义依赖或插件的版本号。
spring-boot-dependencies 通过 dependencyManagement 、pluginManagement 和 properties等元素对一些常用技术框架的依赖或插件进行了统一版本管理,例如 Activemq、Spring、Tomcat 等。