更新時間:2021-06-22 16:31:11 來源:動力節(jié)點 瀏覽1689次
面試的時候經(jīng)常會被問到,spring和springboot的區(qū)別。或者SpringMVC和Springboot的區(qū)別。其實這樣的問法就不是特別合適。因為spring、springboot、springmvc他們?nèi)齻€在spring體系中就不在同一個維度。
spring家族有很多項目,springboot、spring framework、spring cloud等。
我們常用的也就是,springboot、springcloud、springsecurity、springdata。常說的springmvc只是spring framework的特性之一。
1、內(nèi)嵌Servlet容器,可以直接打成jar包,通過java-jar xx.jar運行項目。
2、提供starter pom系列,簡化maven的依賴加載,減少依賴沖突的發(fā)生。
3、支持自動化配置,如下圖。application.properties文件在引入springboot和未引入springboot時,是不一樣的。
實現(xiàn)的源碼:springboot回去判斷引入的jar包是否有spring.factories文件
EnableAutoConfiguration
Import({AutoConfigurationImportSelector.class})
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());
Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.");
return configurations;
}
總結(jié):springboot 是 spring 家族的一個項目,他的目標是提高使用者的開發(fā)效率。
以上就是動力節(jié)點小編介紹的"Springboot與Spring的比較區(qū)別",希望對大家有幫助,更詳細的Java基礎(chǔ)教程可以登錄動力節(jié)點官網(wǎng)查看,學習中遇到問題,也可以請教在線咨詢,有專業(yè)老師隨時為您服務(wù)。