天天看點

Spring Boot 常用 Starter

Spring Boot 通過 Starter 來提供系統服務,Spring Boot 已經提供了一系列 Starter,也可以開發自己的 Starter。比如需要開發一個 Web 應用,隻要在 pom.xml 中聲明一下即可。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
           

如果項目中用到了 Redis,則使用 spring-boot-starter-data-redis,Spring Boot 會自動為你配置好 Spring 需要的各種配置檔案、Redis 的 jar 包、依賴包,以及合适的版本,下表是 Spring Boot 提供的常用 Starter。

Spring Boot 常用 Starter

名稱 作用
spring-boot-starter-web Web 開發支援,預設使用 Tomcat8
spring-boot-starter-aop AOP 開發支援,使用 AspectJ
spring-boot-starter-jdbc Spring JDBC
spring-boot-starter-data-jpa JPA 方式通路資料庫,使用 Hibernate 作為 JPA實作
spring-boot-starter-data-elasticsearch 內建 Elasticsearch,預設使用 localhost:9200
spring-boot-starter-data-redis 內建 Redis,使用 JRedis,預設連接配接 localhost:6379
spring-boot-starter-cache 緩存,支援多種緩存方式,如本地的、Redis、Ehcache 等
spring-boot-devtools 應用程式快速重新開機工具,提升開發體驗
spring-boot-starter-data-mongodb 內建 MongoDB,預設通路 mongdb://localhost/test
spring-boot-starter-data-neo4j 內建 neo4j,預設通路 localhost:7474
spring-boot-starter-data-gemfire 內建分布式緩存
spring-boot-starter-data-solr 內建 Apache lucene 的搜尋平台,預設通路 http://localhost:8983/solr
spring-boot-starter-data-cassandra 內建 Cassandra,預設通路 localhost:7474
spring-boot-starter-data-ldap 內建 ldap
spring-boot-starter-activemq 消息內建 ActiveMQ 支援
spring-boot-starter-amqp 消息內建 AMQP 協定支援,如支援 RabbitMQ
spring-boot-starter-jta-atomikos 分布式事務支援,使用 atomikos
spring-boot-starter-jta-bitronix 一個開源的分布式事務支援
spring-boot-starter-test 包含 JUnit、Spring Test、Hamcrest、Mockito 等測試工具
spring-boot-starter-webservices webservices 支援
spring-boot-starter-websocket websocket 支援
spring-boot-starter-jersey REST 應用和 Jersey 支援
spring-boot-starter-freemarker Freemarker 支援

相比于 Spring , Spring Boot 具有以下優點:

  • 實作約定大于配置,是一個低配置的應用系統架構。不像 Spring 那樣繁瑣的配置,Spring Boot 不需要配置或者極少配置,就能使用 Spring 大量的功能。
  • 提供了内置的 Tomcat 或者 Jetty 容器。
  • 通過依賴的 jar 包管理、自動裝備技術,容易支援與其他技術體系、工具內建。
  • 支援熱加載,開發體驗好。也支援 Spring Boot 系統監控,友善了解系統運作狀況。

繼續閱讀