在官方文档的第三部分的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的引用

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

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

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

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

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

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

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

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

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

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

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

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.springframework.boot</groupId>
  5. <artifactId>spring-boot-maven-plugin</artifactId>
  6. </plugin>
  7. </plugins>
  8. </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. GDI+重绘笔记

    有的控件不能重载 OnPaint,设置 ControlStyles.UserPaint = true即可 //如果为 true,控件将自行绘制,而不是通过操作系统来绘制. //如果为 false,将不 ...

  2. 如何选择Haproxy和Nginx

    对于做软负载,我们都知道主流的方案有LVS.Haproxy.Nginx!那么对于Haproxy和Nginx,我们如何选择呢?回答这个问题之前,我根据个人使用经验来讲下它们的特点! Haproxy特点 ...

  3. Java常见问题分析(内存溢出、内存泄露、线程阻塞等)

    Java垃圾回收机制(GC) 1.1 GC机制作用 1.2 堆内存3代分布(年轻代.老年代.持久代) 1.3 GC分类 1.4 GC过程 Java应用内存问题分析 2.1 Java内存划分 2.2 J ...

  4. 接口测试 rest-assured 使用指南

    转自:https://testerhome.com/topics/7060 原文:https://github.com/rest-assured/rest-assured/wiki/Usage本文gi ...

  5. MySQL binlog-do-db选项是危险的[转]

    很多人通过 binlog-do-db, binlog-ignore-db, replicate-do-db 和   replicate-ignore-db 来过滤复制(某些数据库), 尽管有些使用, ...

  6. HDU 4355 Party All the Time(三分|二分)

    题意:n个人,都要去參加活动,每一个人都有所在位置xi和Wi,每一个人没走S km,就会产生S^3*Wi的"不舒适度",求在何位置举办活动才干使全部人的"不舒适度&quo ...

  7. ushare编译之 ‘struct sockaddr_storage’ has no member named ‘s_addr’

    编译ushare的时候出现'struct sockaddr_storage' has no member named 's_addr' 这是使用libupnp1.6.19出现版本号不兼容的错误. 解决 ...

  8. 网站添加ico图标

    打开某一个网页会在浏览器的标签栏处显示该网页的标题和图标,当网页被添加到收藏夹或者书签中时也会出现网页的图标,怎么在网页title左边显示网页的logo图标呢? 方法一(被动式): 制作一个ico格式 ...

  9. Node.js 抓取电影天堂新上电影节目单及ftp链接

    代码地址如下:http://www.demodashi.com/demo/12368.html 1 概述 本实例主要使用Node.js去抓取电影的节目单,方便大家使用下载. 2 node packag ...

  10. hint指定index的深入理解

    http://czmmiao.iteye.com/blog/1480247创建一个表,含有位图index和b-tree index SQL> create table t as select o ...