在官方文档的第三部分的13块讲述了引用的管理,官方推荐的是使用Maven和Gradle。

我一直在用的是maven,而且使用maven有些优势–spring-boot-starter-parent,这个部件是maven独有的。

这次我们从这里开始学习。

Maven的用户可以通过继承spring-boot-starter-parent项目来获得一些合理的默认配置。这个parent提供了以下特性:

  • 默认使用Java 8
  • 使用UTF-8编码
  • 一个引用管理的功能,在dependencies里的部分配置可以不用填写version信息,这些version信息会从spring-boot-dependencies里得到继承。
  • 识别过来资源过滤(Sensible resource filtering.)
  • 识别插件的配置(Sensible plugin configuration (exec plugin, surefire, Git commit ID, shade).)
  • 能够识别application.properties和application.yml类型的文件,同时也能支持profile-specific类型的文件(如: application-foo.properties and application-foo.yml,这个功能可以更好的配置不同生产环境下的配置文件)。
  • maven把默认的占位符${…​}改为了@..@(这点大家还是看下原文自己理解下吧,我个人用的也比较少 
    since the default config files accept Spring style placeholders (${…​}) the Maven filtering is changed to use @..@ placeholders (you can override that with a Maven property resource.delimiter).)

spring-boot-starter-parent的引用

<!-- Inherit defaults from Spring Boot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

如果dependencies中的一些引用不想使用默认的版本,可以直接加上version信息,把默认的覆盖掉。

另外官方提供的覆盖默认配置的方式如下:

<properties>
<spring-data-releasetrain.version>Fowler-SR2</spring-data-releasetrain.version>
</properties>
  • 1
  • 2
  • 3

在properties中注明某个引用要使用的版本。具体使用哪种方式还是看个人习惯。

如果不想使用spring-boot-starter-parent,也可以自己来配置所要使用的版本:

<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

但是,这种方式下如果想要某些引用的版本特殊说明,就要在上面的声明之前配置:

<dependencyManagement>
<dependencies>
<!-- Override Spring Data release train provided by Spring Boot -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Fowler-SR2</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

这里的引用声明是借助scope=import 来实现的。

如果想要把项目打包成一个可执行的jar包,需要添加maven的一下组件:

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

这里前边文章中都有说过,位置一般都是放在dependencies之后。

版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/qq_35981283/article/details/77802771

spring-boot-starter-parent的更多相关文章

  1. 手把手教你定制标准Spring Boot starter,真的很清晰

    写在前面 我们每次构建一个 Spring 应用程序时,我们都不希望从头开始实现具有「横切关注点」的内容:相反,我们希望一次性实现这些功能,并根据需要将它们包含到任何我们要构建的应用程序中 横切关注点 ...

  2. 从零开始开发一个Spring Boot Starter

    一.Spring Boot Starter简介 Starter是Spring Boot中的一个非常重要的概念,Starter相当于模块,它能将模块所需的依赖整合起来并对模块内的Bean根据环境( 条件 ...

  3. Spring Boot Starter 介绍

    http://www.baeldung.com/spring-boot-starters 作者:baeldung 译者:http://oopsguy.com 1.概述 依赖管理是任何复杂项目的关键部分 ...

  4. spring -boot s-tarter 详解

    Starter POMs是可以包含到应用中的一个方便的依赖关系描述符集合.你可以获取所有Spring及相关技术的一站式服务,而不需要翻阅示例代码,拷贝粘贴大量的依赖描述符.例如,如果你想使用Sprin ...

  5. Spring Boot (一): Spring Boot starter自定义

    前些日子在公司接触了spring boot和spring cloud,有感于其大大简化了spring的配置过程,十分方便使用者快速构建项目,而且拥有丰富的starter供开发者使用.但是由于其自动化配 ...

  6. SpringBoot 之Spring Boot Starter依赖包及作用

    Spring Boot 之Spring Boot Starter依赖包及作用 spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. spri ...

  7. Spring boot starter pom的依赖关系说明

    Spring Boot 通过starter依赖为项目的依赖管理提供帮助.starter依赖起始就是特殊的maven依赖,利用了传递依赖解析,把常用库聚合在一起,组成了几个为特定功能而定制的依赖. sp ...

  8. Spring Boot Starter列表

    转自:http://blog.sina.com.cn/s/blog_798f713f0102wiy5.html Spring Boot Starter 基本的一共有43种,具体如下: 1)spring ...

  9. 创建自己的Spring Boot Starter

    抽取通用模块作为项目的一个spring boot starter.可参照mybatis的写法. IDEA创建Empty Project并添加如下2个module,一个基本maven模块,另一个引入sp ...

  10. 自己写spring boot starter

    自己写spring boot starter 学习了:<spring boot实战>汪云飞著 6.5.4节 pom.xml <project xmlns="http://m ...

随机推荐

  1. POJ2405-Beavergnaw

    Beavergnaw Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6204   Accepted: 4090 Descri ...

  2. Ajax 控件列表名称简介

    ylbtech-ASP.NET AJAX: Ajax 控件列表名称简介   1.A,返回顶部 1) Accordion 可折叠的 2) AlwaysVisibleControl 始终可见控制 3) A ...

  3. 计算机网络自顶向下第三章传输层二TCP

    TCP 全双工 A-B,B-A 点对点 一对一的 TCP连接建立过程 客户首先发送一个特殊的TCP报文段,服务器用另一个特殊的TCP报文段来相应,最后,客户再用第三个特殊的报文段作为相应,前两个报文段 ...

  4. 关于 Android 平台开发相关的有哪些推荐书籍?

    转自:http://www.zhihu.com/question/19579609 作者:Shan Huang 链接:http://www.zhihu.com/question/19579609/an ...

  5. CentOS下iptables 配置详解

    如果你的IPTABLES基础知识还不了解,建议先去看看. 开始配置 我们来配置一个filter表的防火墙. (1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables - ...

  6. 2016.8.22 Axure两级下拉框联动的实现

    刚学Axure,有些很简单的东西都要弄很久,但是弄出来的总归是很开心的. 参考来自:实现省市县下拉框的三级联动 http://www.woshipm.com/rp/348795.html/commen ...

  7. bit、位、byte、字节、B、KB、字符与网速

    一.存储单位bit和Byte 1.bit(比特) bit就是位,也叫比特位,是数据存储的最小单位.简写为小写字母“b” 二进制的一位,每个0或1是一个bit 2.Byte(字节) Byte是字节,也有 ...

  8. jmeter 压测工具

    Apache jmeter 压力测试 java 环境安装 https://www.cnblogs.com/smyhvae/p/3788534.html 下载地址和文档 http://itopic.or ...

  9. WPF 基础到企业应用系列5——WPF千年轮回 续前缘

    一.摘要 首先非常高兴这个系列能得到大家的关注和支持,前端时间身体状况不适,所以暂停了更新,对此表示非常抱歉,以后会逐渐加快进度.只是因为这是一个非常长的系列,我也想把它写好,所以以后也会慢慢来,在这 ...

  10. hdu 4372 第一类斯特林数

    #include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...