<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies>
- 先觀察一下上面的配置,有沒有發現什么?沒錯,都沒有版本號。好神奇呀!怎么做到的?
答:這就是SpringBoot自動配置的強大魅力。在我們創建一個SpringBoot項目的時候,我們的項目其實都會繼承spring-boot-starter-parent項目,這是SpringBoot提供的一個啟動器父級工程,在這個項目里面SpringBoot對所有可能用到的組件的版本號進行了統一管理。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent>
你再也不用擔心使用某個組件會不會產生沖突問題了。SpringBoot說:一切都有我!