13.5. Starts

Starters是一个依赖描述符的集合,你可以将它包含进项目中,这样添加依赖就非常方便。你可以获取所有Spring及相关技术的一站式服务,而不需要翻阅示例代码,拷贝粘贴大量的依赖描述符。例如,如果你想使用Spring和JPA进行数据库访问,只需要在项目中包含 spring-boot-starter-data-jpa 依赖,然后你就可以开始了。该starters包含很多搭建,快速运行项目所需的依赖,并提供一致的,可管理传递性的依赖集。

第三方starters不应该以spring-boot 开头,因为它跟Spring Boot官方artifacts冲突。一个acme的第三方starter通常命名为acmespring-boot-starter

具体的依赖传递过程如下图所示: dependency 首先,我们的项目继承了spring-boot-starter-parent,而spring-boot-starter-parent项目继承了spring-boot-dependencies,因此我们的项目可以使用这两个项目pom中的属性和依赖管理。

然后,spring-boot-starters是所有starter类型项目的父项目,该项目继承了spring-boot-parentspring-boot-parent继承了spring-boot-dependencies,因此spring-boot-starters项目可以使用依赖管理。

接着,spring-boot-starters使用Maven 聚合的方式,聚合了诸如spring-boot-starter-xx的模块(module),这些项目中定义了具体需要用到的依赖(jar包),但本身没有代码只有一个pom.xml,在dependence里引入这些项目,就等于将它们pom定义里的依赖引入到当前我们的项目,从而又形成了依赖树 dependence tree

由上图可以看出,因为spring-boot-starter-xx项目都经过严密的测试,因此其相互依赖版本是一致且安全的,spring-boot-starter依赖spring-boot依赖spring-core,而spring-boot-starter自身又依赖spring-core,但由于spring-core版本相同,因此不存在冲突(没有两个不同版本的相同的依赖jar包),这就是spring-boot-starter-xx另一个好处了,可以放心使用

IDEA用户可以在maven插件中直接查看依赖树 idea dependence tree

使用Maven命令查看依赖树

# 查看依赖树
mvn dependency:tree -Dverbose

spring-boot-starter-xx的模块也不需要指定<version>,因为这个已经定义在它的父pomspring-boot-dependencies里了

最后,我们在自己的项目里<dependences>导入spring-boot-starter-xx,就是将它代表的功能模块需要的依赖带入项目中,而不需要挨个复制具体的jar包,且不需要指定具体<version>

所谓Maven的聚合就是通过一个父项目,将所有子项目以module的方式组合在该父项目的POM下(该父项目只有一个pomx.xml),子项目继承该父项目,同时子项目间可以互相依赖

Table Spring Boot application starters

具体见spring-boot-reference

NameDescriptionPom

spring-boot-starter

Core starter, including auto-configuration support, logging and YAML

Pom

spring-boot-starter-activemq

Starter for JMS messaging using Apache ActiveMQ

Pom

spring-boot-starter-amqp

Starter for using Spring AMQP and Rabbit MQ

Pom

spring-boot-starter-aop

Starter for aspect-oriented programming with Spring AOP and AspectJ

Pom

spring-boot-starter-artemis

Starter for JMS messaging using Apache Artemis

Pom

spring-boot-starter-batch

Starter for using Spring Batch

Pom

spring-boot-starter-cache

Starter for using Spring Framework’s caching support

Pom

spring-boot-starter-cloud-connectors

Starter for using Spring Cloud Connectors which simplifies connecting to services in cloud platforms like Cloud Foundry and Heroku

Pom

spring-boot-starter-data-cassandra

Starter for using Cassandra distributed database and Spring Data Cassandra

Pom

spring-boot-starter-data-couchbase

Starter for using Couchbase document-oriented database and Spring Data Couchbase

Pom

spring-boot-starter-data-elasticsearch

Starter for using Elasticsearch search and analytics engine and Spring Data Elasticsearch

Pom

spring-boot-starter-data-gemfire

Starter for using GemFire distributed data store and Spring Data GemFire

Pom

spring-boot-starter-data-jpa

Starter for using Spring Data JPA with Hibernate

Pom

spring-boot-starter-data-ldap

Starter for using Spring Data LDAP

Pom

spring-boot-starter-data-mongodb

Starter for using MongoDB document-oriented database and Spring Data MongoDB

Pom

spring-boot-starter-data-neo4j

Starter for using Neo4j graph database and Spring Data Neo4j

Pom

spring-boot-starter-data-redis

Starter for using Redis key-value data store with Spring Data Redis and the Jedis client

Pom

spring-boot-starter-data-rest

Starter for exposing Spring Data repositories over REST using Spring Data REST

Pom

spring-boot-starter-data-solr

Starter for using the Apache Solr search platform with Spring Data Solr

Pom

spring-boot-starter-freemarker

Starter for building MVC web applications using FreeMarker views

Pom

spring-boot-starter-groovy-templates

Starter for building MVC web applications using Groovy Templates views

Pom

spring-boot-starter-hateoas

Starter for building hypermedia-based RESTful web application with Spring MVC and Spring HATEOAS

Pom

spring-boot-starter-integration

Starter for using Spring Integration

Pom

spring-boot-starter-jdbc

Starter for using JDBC with the Tomcat JDBC connection pool

Pom

spring-boot-starter-jersey

Starter for building RESTful web applications using JAX-RS and Jersey. An alternative to spring-boot-starter-web

Pom

spring-boot-starter-jooq

Starter for using jOOQ to access SQL databases. An alternative to spring-boot-starter-data-jpa or spring-boot-starter-jdbc

Pom

spring-boot-starter-jta-atomikos

Starter for JTA transactions using Atomikos

Pom

spring-boot-starter-jta-bitronix

Starter for JTA transactions using Bitronix

Pom

spring-boot-starter-jta-narayana

Spring Boot Narayana JTA Starter

Pom

spring-boot-starter-mail

Starter for using Java Mail and Spring Framework’s email sending support

Pom

spring-boot-starter-mobile

Starter for building web applications using Spring Mobile

Pom

spring-boot-starter-mustache

Starter for building MVC web applications using Mustache views

Pom

spring-boot-starter-security

Starter for using Spring Security

Pom

spring-boot-starter-social-facebook

Starter for using Spring Social Facebook

Pom

spring-boot-starter-social-linkedin

Stater for using Spring Social LinkedIn

Pom

spring-boot-starter-social-twitter

Starter for using Spring Social Twitter

Pom

spring-boot-starter-test

Starter for testing Spring Boot applications with libraries including JUnit, Hamcrest and Mockito

Pom

spring-boot-starter-thymeleaf

Starter for building MVC web applications using Thymeleaf views

Pom

spring-boot-starter-validation

Starter for using Java Bean Validation with Hibernate Validator

Pom

spring-boot-starter-web

Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container

Pom

spring-boot-starter-web-services

Starter for using Spring Web Services

Pom

spring-boot-starter-websocket

Starter for building WebSocket applications using Spring Framework’s WebSocket support

Pom

results matching ""

    No results matching ""