Spring Boot開啟的2種方式詳解
Spring Boot依賴
使用Spring Boot很簡單,先添加基礎(chǔ)依賴包,有以下兩種方式
1. 繼承spring-boot-starter-parent項目
<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項目依賴
<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依賴注意點
1. 屬性覆蓋只對繼承有效
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綁定的,如果要修改里面組件的版本,只需要添加如下屬性覆蓋即可,但這種方式只對繼承有效,導(dǎo)入的方式無效。
<properties> <slf4j.version>1.7.25<slf4j.version> </properties>
如果導(dǎo)入的方式要實現(xiàn)版本的升級,達(dá)到上面的效果,這樣也可以做到,把要升級的組件依賴放到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的依賴組件版本可能會造成不兼容的問題。
2. 資源文件過濾問題
使用繼承Spring Boot時,如果要使用Maven resource filter過濾資源文件時,資源文件里面的占位符為了使${}和Spring Boot區(qū)別開來,此時要用@...@包起來,不然無效。另外,@...@占位符在yaml文件編輯器中編譯報錯,所以使用繼承方式有諸多問題,坑要慢慢趟。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
springboot+EHcache 實現(xiàn)文章瀏覽量的緩存和超時更新
這篇文章主要介紹了springboot+EHcache 實現(xiàn)文章瀏覽量的緩存和超時更新,問題描述和解決思路給大家介紹的非常詳細(xì),需要的朋友可以參考下2017-04-04如何利用Java輸出鏈表中倒數(shù)第k個結(jié)點
這篇文章主要給大家介紹了關(guān)于如何利用Java輸出鏈表中倒數(shù)第k個結(jié)點的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用java具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2021-12-12Spring中配置Transaction與不配置的區(qū)別及說明
這篇文章主要介紹了Spring中配置Transaction與不配置的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07spring security獲取用戶信息的實現(xiàn)代碼
這篇文章主要介紹了spring security獲取用戶信息的實現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12