javascript
Spring Boot开启的2种方式
?
Spring Boot依賴
使用Spring Boot很簡單,先添加基礎依賴包,有以下兩種方式
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. 導入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依賴包里面的組件的版本都是和當前Spring Boot綁定的,如果要修改里面組件的版本,只需要添加如下屬性覆蓋即可,但這種方式只對繼承有效,導入的方式無效。
<properties><slf4j.version>1.7.25<slf4j.version> </properties>如果導入的方式要實現版本的升級,達到上面的效果,這樣也可以做到,把要升級的組件依賴放到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區別開來,此時要用@...@包起來,不然無效。另外,@...@占位符在yaml文件編輯器中編譯報錯,所以使用繼承方式有諸多問題,坑要慢慢趟。
總結
以上是生活随笔為你收集整理的Spring Boot开启的2种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何在一分钟内搞定面试官?
- 下一篇: gradle idea java ssm