天天看點

什麼是Spring Boot?

什麼是Spring Boot?

Spring Boot是Spring開源組織下的子項目,是Spring元件一站式解決方案,主要是簡化了使用Spring的難度,簡省了繁重的配置,提供了各種啟動器,開發者能快速上手。

官方網站:

http://projects.spring.io/spring-boot/\ GitHub源碼: https://github.com/spring-projects/spring-boot

Spring Boot的優點

Features

Create stand-alone Spring applications

Embed Tomcat, Jetty or Undertow directly (no need to deploy WAR files)

Provide opinionated ‘starter’ POMs to simplify your Maven configuration

Automatically configure Spring whenever possible

Provide production-ready features such as metrics, health checks and externalized configuration

Absolutely no code generation and no requirement for XML configuration

獨立運作

Spring Boot而且内嵌了各種servlet容器,Tomcat、Jetty等,現在不再需要打成war包部署到容器中,Spring Boot隻要打成一個可執行的jar包就能獨立運作,所有的依賴包都在一個jar包内。

簡化配置

spring-boot-starter-web啟動器自動依賴其他元件,簡少了maven的配置。

+- org.springframework.boot:spring-boot-starter-web:jar:1.5.6.RELEASE:compile
+- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.6.RELEASE:compile
|  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.16:compile
|  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.16:compile
|  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.16:compile
+- org.hibernate:hibernate-validator:jar:5.3.5.Final:compile
|  +- javax.validation:validation-api:jar:1.1.0.Final:compile
|  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
|  \- com.fasterxml:classmate:jar:1.3.3:compile
\- org.springframework:spring-webmvc:jar:4.3.10.RELEASE:compile      

自動配置

Spring Boot能根據目前類路徑下的類、jar包來自動配置bean,如添加一個spring-boot-starter-web啟動器就能擁有web的功能,無需其他配置。

無代碼生成和XML配置

Spring Boot配置過程中無代碼生成,也無需XML配置檔案就能完成所有配置工作,這一切都是借助于條件注解完成的,這也是Spring4.x的核心功能之一。

應用監控

Spring Boot提供一系列端點可以監控服務及應用,做健康檢測。

Spring Boot的缺點

Spring Boot雖然上手很容易,但如果你不了解其核心技術及流程,是以一旦遇到問題就很棘手,而且現在的解決方案也不是很多,需要一個完善的過程。