(三)Spring Boot 官网文档学习之默认配置
原文地址:https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/reference/htmlsingle/#using-boot
继承 spring-boot-starter-parent
当我们在 pom
里面继承 spring-boot-starter-parent
的时候,我们将自动的获得一些默认值,这些默认值都是 spring-boot-starter-parent
里面默认配置的;
一般都有下面默认值:
JDK8
将作为默认的编译器;- 所有的编码,都将自动的使用
UTF8
;
还有一些其他默认值,博主初学,暂时也不明白是什么意思,贴出原文,大家自己看看:
A Dependency Management section, inherited from the spring-boot-dependencies pom, that manages the versions of common dependencies. This dependency management lets you omit <version> tags for those dependencies when used in your own pom.
An execution of the repackage goal with a repackage execution id. Sensible resource filtering.
Sensible plugin configuration (exec plugin, Git commit ID, and shade).
Sensible resource filtering for application.properties and application.yml including profile-specific files (for example, application-dev.properties and application-dev.yml)
Note that, since the application.properties and application.yml files accept Spring style placeholders (${…}), the Maven filtering is changed to use @..@ placeholders. (You can override that by setting a Maven property called resource.delimiter.)
覆盖默认配置
继承默认配置以后,还是可以覆盖掉默认配置的;
我们只需要在 <properties>
里面配置,我们想要覆盖的属性的具体版本,即可:
例如,覆盖 spring-data-releasetrain
的默认版本:
<properties>
<spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version>
</properties>
和上一篇,使用没有 <parent>
的 pom
,而使用 spring-boot-dependencies
一样,都可以覆盖默认配置;
启动器
启动器,可以理解为一组配置,被打包成一个依赖包了;
比如我们需要 Spring Framework
框架的缓存功能,则可以在 <dependencies>
里面添加 spring-boot-starter-cache
启动器 依赖;
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
</dependencies>
官方的启动器名字格式都是 spring-boot-starter-*
,在 IDEA
配置好 Maven
以后,可以使用 Ctrl + 空格键
进行智能提示;
官网给出了启动器的列表,以及说明,地址 :Spring Boot 启动器