1. 程式人生 > 程式設計 >SpringBoot啟動器Starters使用及原理解析

SpringBoot啟動器Starters使用及原理解析

Starters是什麼

Starters可以理解為啟動器,它包含了一系列可以整合到應用裡面的依賴包,你可以一站式整合Spring及其他技術,而不需要到處找示例程式碼和依賴包。如你想使用Spring JPA訪問資料庫,只要加入spring-boot-starter-data-jpa啟動器依賴就能使用了。

Starters命名規則

Spring Boot官方的啟動器都是以spring-boot-starter-命名的,代表了一個特定的應用型別。第三方的啟動器不能以spring-boot開頭命名,它們都被Spring Boot官方保留。一般一個第三方的應該這樣命名,像mybatis的mybatis-spring-boot-starter。

啟動器種類

Spring Boot應用啟動器基本的一共有N(現知道的是44)種:具體如下:

spring-boot-starter 這是Spring Boot的核心啟動器,包含了自動配置、日誌和YAML。
spring-boot-starter-actuator 幫助監控和管理應用。
spring-boot-starter-amqp 通過spring-rabbit來支援AMQP協議。
spring-boot-starter-aop 支援面向方面的程式設計即AOP,包括spring-aop和AspectJ。
spring-boot-starter-artemis 通過Apache Artemis支援JMS的API(Java Message Service API)。

spring-boot-starter-batch 支援Spring Batch,包括HSQLDB資料庫。
spring-boot-starter-cache 支援Spring的Cache抽象。
spring-boot-starter-cloud-connectors 支援Spring Cloud Connectors,簡化了在像Cloud Foundry或Heroku這樣的雲平臺上連線服務。
spring-boot-starter-data-elasticsearch 支援ElasticSearch搜尋和分析引擎,包括spring-data-elasticsearch。
spring-boot-starter-data-gemfire 支援GemFire分散式資料儲存,包括spring-data-gemfire。
spring-boot-starter-data-jpa 支援JPA、包括spring-data-jpa、spring-orm、Hibernate。
spring-boot-starter-data-mongodb 支援MongoDB資料,包括spring-data-mongodb。
spring-boot-starter-data-rest 支援通過REST暴露Spring Data資料倉庫。
spring-boot-starter-data-solr 支援Apache Solr搜尋平臺,包括spring-data-solr。
spring-boot-starter-freemarker 支援FreeMarker模板引擎。
spring-boot-starter-groovy-templates 支援Groovy模板引擎。
spring-boot-starter-hateoas 通過spring-hateoas支援基於HATEOAS的RESTful Web服務。
spring-boot-starter-hornetq 通過HornetQ支援JMS。
spring-boot-starter-integration 支援通用的spring-integration模組。
spring-boot-starter-jdbc 支援JDBC資料庫。
spring-boot-starter-jersey 支援Jersey RESTful Web服務框架。
spring-boot-starter-jta-atomikos 通過Atomikos支援JTA分散式事務處理。
spring-boot-starter-jta-bitronix 通過Bitronix支援JTA分散式事務處理。
spring-boot-starter-mail 支援javax.mail模組。
spring-boot-starter-mobile 支援spring-mobile。
spring-boot-starter-mustache 支援Mustache模板引擎。
spring-boot-starter-redis 支援Redis鍵值儲存資料庫,包括spring-redis。
spring-boot-starter-security 支援spring-security。
spring-boot-starter-social-facebook 支援spring-social-facebook
spring-boot-starter-social-linkedin 支援pring-social-linkedin
spring-boot-starter-social-twitter 支援pring-social-twitter
spring-boot-starter-test 支援常規測試依賴,包括JUnit、Hamcrest、Mockito、spring-test模組。
spring-boot-starter-thymeleaf 支援Thymeleaf模板引擎,包括與Spring的整合。
spring-boot-starter-velocity 支援Velocity模板引擎。
spring-boot-starter-web 支援全棧式Web開發,包括Tomcat和spring-webmvc。
spring-boot-starter-websocket 支援WebSocket開發。
spring-boot-starter-ws 支援Spring Web Services。

Spring Boot應用啟動器面向生產環境的還有2種,具體如下:

spring-boot-starter-actuator 增加了面向產品上線相關的功能,比如測量和監控。
spring-boot-starter-remote-shell 增加了遠端ssh shell的支援。

最後,Spring Boot應用啟動器還有一些替換技術的啟動器,具體如下:

spring-boot-starter-jetty 引入了Jetty HTTP引擎(用於替換Tomcat)。
spring-boot-starter-log4j 支援Log4J日誌框架。
spring-boot-starter-logging 引入了Spring Boot預設的日誌框架Logback。
spring-boot-starter-tomcat 引入了Spring Boot預設的HTTP引擎Tomcat。
spring-boot-starter-undertow 引入了Undertow HTTP引擎(用於替換Tomcat)。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。