Spring IO Platform簡(jiǎn)單介紹
Spring IO Platform框架簡(jiǎn)單來說就是一個(gè)版本號(hào)兼容系統(tǒng),它將常用第三方類庫的兼容的版本組織起來。只要我們?cè)陧?xiàng)目中引用了Spring IO Platform,就不需要為這些第三方類庫設(shè)置版本號(hào)了,Spring IO Platform會(huì)自動(dòng)幫我們?cè)O(shè)置所有兼容的版本號(hào)。本文參考自官方文檔,如果需要查閱詳細(xì)信息,請(qǐng)直接看原文即可。
引入類庫
使用Maven
使用Maven的話,在pom.xml中修改為類似這樣的。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>your-application</artifactId>
<version>1.0.0-SNAPSHOT</version>
<!-- 添加以下一段-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Dependency declarations -->
</project>
或者將設(shè)置Spring IO Platform為父項(xiàng)目也行
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>your-application</artifactId>
<version>1.0.0-SNAPSHOT</version>
<parent>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>Brussels-SR3</version>
<relativePath/>
</parent>
<!-- Dependency declarations -->
</project>
設(shè)置完成后,以后添加依賴項(xiàng)就不需要指定版本好了??梢韵裣旅孢@樣添加依賴。
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<!-- 沒有版本號(hào) -->
</dependency>
</dependencies>
使用Gradle
如果用Gradle的話,就稍微復(fù)雜一點(diǎn)了。因?yàn)镚radle沒有dependencyManagement這么一個(gè)功能,所以還需要額外的插件。總之,將build.gradle文件修改為類似這樣即可。
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE'
}
}
apply plugin: 'io.spring.dependency-management'
repositories {
mavenCentral()
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:Brussels-SR3'
}
}
然后,聲明依賴就不需要版本號(hào)了。
dependencies {
compile 'org.springframework:spring-core'
}
覆蓋版本號(hào)
有時(shí)候可能需要覆蓋Spring IO Platform中的版本號(hào),改為使用我們自己指定的版本號(hào)。如果使用Maven的話,在pom.xml文件的properties節(jié)點(diǎn)中修改版本號(hào)。
<properties> <foo.version>1.1.0.RELEASE</foo.version> </properties>
如果使用Gradle的話,在build.gradle中添加ext屬性即可。
ext['foo.version'] = '1.1.0.RELEASE'
或者
ext {
foo.version = '1.1.0.RELEASE'
}
也可以在gradle.properties文件中設(shè)置。
foo.version=1.1.0.RELEASE
已知問題
由于谷歌Guava類庫的廣泛使用,引用不同的項(xiàng)目時(shí)可能存在不兼容情況。這時(shí)候需要我們手動(dòng)指定合適的版本號(hào)以保證項(xiàng)目能夠正常運(yùn)行。
如果想詳細(xì)了解Spring IO Platform的版本號(hào),可以查看官方文檔附錄。
示例程序
其實(shí)這篇文章到這里就可以結(jié)束了,因?yàn)镾pring IO Platform實(shí)際上確實(shí)也沒有多少東西要講。
這是我的一個(gè)小小例子,用Spring IO Platform和Gradle構(gòu)建的一個(gè)Spring MVC程序。下面是對(duì)應(yīng)的build.gradle文件。可以看到由于使用了Spring IO Platform,所以這里的依賴項(xiàng)全部沒有指定版本號(hào)。
group 'yitian.study'
version '1.0-SNAPSHOT'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
dependencies {
testCompile group: 'junit', name: 'junit'
compile 'org.springframework:spring-webmvc'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging'
}
dependencyManagement {
imports {
mavenBom 'io.spring.platform:platform-bom:Brussels-SR3'
}
}
從IDE的提示可以看到,所有版本號(hào)都由Spring IO Platform正確處理了。

完整的例子在這里,雖然我感覺大部分不需要看這個(gè)。
總結(jié)
以上就是本文關(guān)于Spring IO Platform簡(jiǎn)單介紹的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
- springboot使用JdbcTemplate完成對(duì)數(shù)據(jù)庫的增刪改查功能
- 基于spring boot 1.5.4 集成 jpa+hibernate+jdbcTemplate(詳解)
- spring整合redis以及使用RedisTemplate的方法
- spring使用RedisTemplate的操作類訪問Redis
- SpringBoot用JdbcTemplates訪問Mysql實(shí)例代碼
- 詳解spring boot中使用JdbcTemplate
- Spring Boot中使用jdbctemplate 操作MYSQL數(shù)據(jù)庫實(shí)例
- 淺析Spring的JdbcTemplate方法
相關(guān)文章
Spring?MVC文件請(qǐng)求處理MultipartResolver詳解
這篇文章主要介紹了Spring?MVC文件請(qǐng)求處理詳解:MultipartResolver,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-11-11
SpringBoot+SpringSecurity實(shí)現(xiàn)認(rèn)證的流程詳解
這篇文章主要介紹了SpringBoot+SpringSecurity實(shí)現(xiàn)認(rèn)證的流程,文中通過代碼示例和圖文結(jié)合的方式講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-05-05
idea企業(yè)開發(fā)之新建各類型項(xiàng)目的詳細(xì)教程
這篇文章主要介紹了idea企業(yè)開發(fā)之新建各類型項(xiàng)目的詳細(xì)教程,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
spring boot使用i18n時(shí)properties文件中文亂碼問題的解決方法
這篇文章主要介紹了spring boot使用i18n時(shí)properties文件中文亂碼問題的解決方法,需要的朋友可以參考下2017-11-11
如何通過Maven倉庫安裝Spire系列的Java產(chǎn)品
這篇文章主要介紹了如何通過Maven倉庫安裝Spire系列的Java產(chǎn)品,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07
java Spring MVC4環(huán)境搭建實(shí)例詳解(步驟)
spring WEB MVC框架提供了一個(gè)MVC(model-view-controller)模型-視圖-控制器的結(jié)構(gòu)和組件,利用它可以開發(fā)更靈活、松耦合的web應(yīng)用。MVC模式使得整個(gè)服務(wù)應(yīng)用的各部分(控制邏輯、業(yè)務(wù)邏輯、UI界面展示)分離開來,使它們之間的耦合性更低2017-08-08
基于@MapperScan和@ComponentScan的使用區(qū)別
這篇文章主要介紹了@MapperScan和@ComponentScan的使用區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09

