简介:
Spring IO Platform是Spring官网中排第一位的项目。它将Spring的核心API集成到一个适用于现代应用程序的平台中。提供了Spring项目组合中的版本依赖。这些依赖关系是经过测试,可以保证正常工作。
为什么要使用?
Spring IO Platform主要是解决依赖版本的冲突问题。举个栗子:在使用Spring的时候,经常会使用到第三方库,一般大家都是根据经验挑选一个版本浩或挑选最新的,其实这是存在隐患的。除非做过完整的测试,保证集成该版本的依赖不会出现问题,否则风险很大,且后续扩展会越来越困难。因为随着业务复杂度的增加,集成的第三方组件会越来会多,依赖之间的关联也会也来越复杂。
Spring IO Platform正好解决了这些问题,在我们添加第三方依赖时,不需要写版本号,它能自动帮我们选择一个最优的版本,保证最大限度的扩展。
维护了哪些依赖?
Spring IO Platform维护的依赖非常多,挑选了一些常见的(更多详情请查看官网),如下表所示:
Group | Artifact | Version |
---|---|---|
org.springframework.boot | spring-boot | 1.5.10.RELEASE |
ch.qos.logback | logback-core | 1.1.11 |
com.google.code.gson | gson | 2.8.2 |
com.rabbitmq | amqp-client | 4.0.3 |
com.rabbitmq | http-client | 1.1.1.RELEASE |
junit | junit | 4.12 |
org.apache.tomcat | tomcat-jdbc | 8.5.27 |
使用Spring IO Platform
Spring IO Platform主要用于管理系统依赖,可以支持Maven和Gradle。
在Maven中使用Spring IO Platform
Spring IO Platform支持import和继承parent两种方式:
import的方式:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
6 <modelVersion>4.0.0</modelVersion>
7
8 <groupId>com.example</groupId>
9 <artifactId>your-application</artifactId>
10 <version>1.0.0-SNAPSHOT</version>
11
12 <dependencyManagement>
13 <dependencies>
14 <dependency>
15 <groupId>io.spring.platform</groupId>
16 <artifactId>platform-bom</artifactId>
17 <version>Brussels-SR7</version>
18 <type>pom</type>
19 <scope>import</scope>
20 </dependency>
21 </dependencies>
22 </dependencyManagement>
23 <!-- Dependency declarations -->
24 </project>
继承parent的方式:
1 <?xml version="1.0" encoding="UTF-8"?>
2 <project xmlns="http://maven.apache.org/POM/4.0.0"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5 <modelVersion>4.0.0</modelVersion>
6 <groupId>com.example</groupId>
7 <artifactId>your-application</artifactId>
8 <version>1.0.0-SNAPSHOT</version>
9 <parent>
10 <groupId>io.spring.platform</groupId>
11 <artifactId>platform-bom</artifactId>
12 <version>Brussels-SR7</version>
13 <relativePath/>
14 </parent>
15 <!-- Dependency declarations -->
16 </project>
采用继承parent的方法,除了导入pom提供的依赖关系管理之外,应用程序还将获得一些插件管理,为许多插件提供合理的默认设置,包括Spring Boot的Maven插件。 要利用这个默认配置,需要做的就是把这个插件包含在你的pom的<plugins>部分中:
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>
当想在自己的pom里添加了一个属于Spring IO Platform中的依赖的时候,可以直接省略版本号,如下所示:
1 <dependencies>
2 <dependency>
3 <groupId>org.springframework</groupId>
4 <artifactId>spring-core</artifactId>
5 </dependency>
6 </dependencies>
在Gradle中使用Spring IO Platform
如下所示,我们会应用io.spring.dependency-management这个插件,然后在dependencyManagement中导入bom
1 buildscript {
2 repositories {
3 jcenter()
4 }
5 dependencies {
6 classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE'
7 }
8 }
9 apply plugin: 'io.spring.dependency-management'
10 repositories {
11 mavenCentral()
12 }
13 dependencyManagement {
14 imports {
15 mavenBom 'io.spring.platform:platform-bom:Brussels-SR7'
16 }
17 }
当需要添加一个属于Spring IO Platform中的依赖的时候,写法与Maven类似,可以省略版本号,如下所示:
1 dependencies {
2 compile 'org.springframework:spring-core'
3 }
喜欢请微信扫描下面二维码,关注我公众号--“精修Java”,做一些实战项目中的问题和解决方案分享。
来源:oschina
链接:https://my.oschina.net/u/4384545/blog/4251262