1.发现每个新建的springboot项目都有一个父依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
2.每个springboot-web项目都有依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3.总结
1.首先springboot的核心就是starter模块核心依赖和autoconfiguration自动配置
starter:每个spring框架都有与之对应的starter,如springmvc有spring-boot-starter-web
spring-boot-starter-web内置web容器tomcate等
autoconfiguration:自动化配置为springboot项目简化了繁琐的配置文件;核心就是通过@SpringBootApplication继承了
@SpringBootConfiguration和@EnableAutoConfiguration和@ComponentScan这三个注解;而配置文件
application.yml和@configuration定义的类的配置能够生效,就是靠autoconfiguration;可以通过
spring-boot-autoconfigration-1.2.*.RELEASE.jar里面的spring-configuration-metadata.json看到所有当前
starter(框架)下面所有定义的配置属性。
2.spring-boot-starter-parent是一个springboot项目的父工程,它定义了很多当前项目的规范
1.定义了 Java 编译版本为 1.8 。
2.使用 UTF-8 格式编码。
3.继承自 spring-boot-dependencies,这个里边定义了依赖的版本,也正是因为继承了这个依赖,所以我们在写依赖时才
不需要写版本号。
4.执行打包操作的配置。
5.自动化的资源过滤。
6.自动化的插件配置。
7.针对 application.properties 和 application.yml 的资源过滤,包括通过 profile 定义的不同环境的配置文件,
例如 application-dev.properties 和 application-dev.yml。
3.所以一般的maven父pom工程都继承spring-boot-dependencies;如
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
这样写之后,依赖的版本号问题虽然解决了,但是关于打包的插件、编译的 JDK 版本、文件的编码格式等等
这些配置,在没有 parent 的时候,这些统统要自己去配置。