Spring Boot 常用 Starter
阿新 • • 發佈:2018-11-19
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-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 系統監控,方便了解系統執行狀況。