Spring Boot開(kāi)啟的2種方式詳解
Spring Boot依賴
使用Spring Boot很簡(jiǎn)單,先添加基礎(chǔ)依賴包,有以下兩種方式
1. 繼承spring-boot-starter-parent項(xiàng)目
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version> </parent>
2. 導(dǎo)入spring-boot-dependencies項(xiàng)目依賴
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencyManagement>
Spring Boot依賴注意點(diǎn)
1. 屬性覆蓋只對(duì)繼承有效
This only works if your Maven project inherits (directly or indirectly) from spring-boot-dependencies. If you have added spring-boot-dependencies in your own dependencyManagement section withimportyou have to redefine the artifact yourself instead of overriding the property.
Spring Boot依賴包里面的組件的版本都是和當(dāng)前Spring Boot綁定的,如果要修改里面組件的版本,只需要添加如下屬性覆蓋即可,但這種方式只對(duì)繼承有效,導(dǎo)入的方式無(wú)效。
<properties> <slf4j.version>1.7.25<slf4j.version> </properties>
如果導(dǎo)入的方式要實(shí)現(xiàn)版本的升級(jí),達(dá)到上面的效果,這樣也可以做到,把要升級(jí)的組件依賴放到Spring Boot之前。
<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>1.5.6.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
Each Spring Boot release is designed and tested against a specific set of third-party dependencies. Overriding versions may cause compatibility issues.
需要注意,要修改Spring Boot的依賴組件版本可能會(huì)造成不兼容的問(wèn)題。
2. 資源文件過(guò)濾問(wèn)題
使用繼承Spring Boot時(shí),如果要使用Maven resource filter過(guò)濾資源文件時(shí),資源文件里面的占位符為了使${}和Spring Boot區(qū)別開(kāi)來(lái),此時(shí)要用@...@包起來(lái),不然無(wú)效。另外,@...@占位符在yaml文件編輯器中編譯報(bào)錯(cuò),所以使用繼承方式有諸多問(wèn)題,坑要慢慢趟。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
springboot+EHcache 實(shí)現(xiàn)文章瀏覽量的緩存和超時(shí)更新
這篇文章主要介紹了springboot+EHcache 實(shí)現(xiàn)文章瀏覽量的緩存和超時(shí)更新,問(wèn)題描述和解決思路給大家介紹的非常詳細(xì),需要的朋友可以參考下2017-04-04如何利用Java輸出鏈表中倒數(shù)第k個(gè)結(jié)點(diǎn)
這篇文章主要給大家介紹了關(guān)于如何利用Java輸出鏈表中倒數(shù)第k個(gè)結(jié)點(diǎn)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用java具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2021-12-12Spring中配置Transaction與不配置的區(qū)別及說(shuō)明
這篇文章主要介紹了Spring中配置Transaction與不配置的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07Java中監(jiān)聽(tīng)器Listener詳解
Listener是由Java編寫(xiě)的WEB組件,主要完成對(duì)內(nèi)置對(duì)象狀態(tài)的變化 (創(chuàng)建、銷毀)和屬性的變化進(jìn)行監(jiān)聽(tīng),做進(jìn)一步的處理,主要對(duì)session和application內(nèi)置對(duì)象監(jiān)聽(tīng),這篇文章主要介紹了Java中監(jiān)聽(tīng)器Listener,需要的朋友可以參考下2023-08-08詳解Java TCC分布式事務(wù)實(shí)現(xiàn)原理
這篇文章主要介紹了詳解Java TCC分布式事務(wù)實(shí)現(xiàn)原理,對(duì)分布式事務(wù)感興趣的同學(xué),一定要看一下2021-04-04spring security獲取用戶信息的實(shí)現(xiàn)代碼
這篇文章主要介紹了spring security獲取用戶信息的實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12