組件自動裝配:規約大於配置,專一於核心業務外部化配置:一次構建、按需調配,處處運行java
嵌入式容器:內置容器、無需部署、獨立運行web
Spring Boot Starter : 簡化依賴、按需裝配、自我包容spring
Production-Ready : 一站式運維、生態無縫整合sql
組件自動裝配:模式註解、@Enable模塊、條件裝配、加載機制外部化配置:Environment抽象、生命週期、破壞性變動編程
嵌入式容器:Servlet Web容器、Reactive Web 容器跨域
Spring Boot Starter: 依賴管理、裝配條件、裝配順序緩存
Production-Ready: 健康檢查、數據指標、@Endpoint管控tomcat
//在SpringBootApplication中也是包含了EnableAutoConfiguration @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }
查看源碼,包含EnableAutoConfiguration,所以咱們直接啓動DemoApplication是成功的。架構
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration @ComponentScan( excludeFilters = {@Filter( type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class} ), @Filter( type = FilterType.CUSTOM, classes = {AutoConfigurationExcludeFilter.class} )} ) public @interface SpringBootApplication{}
而對於配置文件,在Spring中是大部分存在的。app
【圖片】
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
2018-10-10 11:23:56.607 INFO 21788 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet com.myself.demo.web.servlet.MyServlet mapped to [/my/servlet]
@WebServlet(urlPatterns = "/my/servlet",asyncSupported = true
//映射、繼承HttpServlet編程規範 ,asyncSupported支持異步處理 @WebServlet(urlPatterns = "/my/servlet",asyncSupported = true) public class MyServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { //開始異步操做 AsyncContext asyncContext = req.startAsync(); //啓動 asyncContext.start(()->{ try { resp.getWriter().println("Hello,World!"); //觸發完成 asyncContext.complete(); } catch (IOException e) { e.printStackTrace(); } }); } }
注意:異步較爲複雜,以上只是一個簡單的實現例子
模版引擎
內容協商
異常處理
@ExceptionHandler
HandlerExceptionResolver --> ExceptionHandlerExceptionResolver
BasicErrorController(Spring Boot 項目默認錯誤頁)
資源服務
資源跨域
服務發現
核心架構
//後續補充
處理流程
//後續補充
核心組件
Web MVC 註解兼容
函數式聲明
異步非阻塞
使用場景
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <!-- Exclude the Tomcat dependency --> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <!-- Use Jetty instead --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency>
//這種狀況下,須要先將其餘外部服務剔除依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency>
Web ServerFactoryCustomizer
ReactiveWebServerFactoryCustomizer
依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>
數據源
自動裝配
依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
實體映射
實體操做
自動裝配
依賴
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </dependency>
Spring事務抽象
JDBC事務抽象
自動裝配
//兩者等價 new SpringApplicationBuilder(DemoApplication.class).run(args); //SpringApplication.run(DemoApplication.class, args);
依賴
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
端點(Endpoints)
健康檢查(Health Checks)
指標(Metrics)
若是本文對你有所幫助,歡迎關注我的技術公衆號