SpringBoot常用的Starter

苏磊
2023-12-01

了解Starter

SpringBoot为了简化配置,提供了非常多的Starter。它先打包好与常用模块相关的所有jar包,并完成自动配置,然后组装成Starter(例如Web相关的SpringMVC、容器等打包好后组装成 spring-boot-starter-web)。这使得在开发业务代码时不需要过多关注框架的配置,只需要关注业务逻辑即可。

SpringBoot提供了很多开箱即用的Starter,大概有近50种,其中常用的整理如下:

starterdesc
spring-boot-starter-web用于构建Web,包含 RESTful 风格框架、SpringMVC和默认的嵌入式容器Tomcat
spring-boot-starter-test用于测试
spring-boot-starter-data-jpa带有Hibermate的Spring Data JPA
spring-boot-starter-jdbc传统的JDBC
spring-boot-starter-thymeleaf支持Thymeleaf模板
spring-boot-starter-mail支持Java Mail、Spring Email 发送邮件
spring-boot-starter-integrationSpring框架创建的一个API,面向企业应用集成(EAI)
spring-boot-starter-mobileSpringMVC的扩展,用来简化手机上的Web应用程序开发
spring-boot-starter-data-redis通过Spring Data Redis、Redis Client使用Redis
spring-boot-starter-validationBean Validation是一个数据验证的规范,Hibernate Validator是一个数据验证框架
spring-boot-starter-websocket相对于非持久的协议HTTP,Websocket 是一个持久化的协议
spring-boot-starter-web-servicesSOAP Web Services
spring-boot-starter-hateoas为服务添加HATEOAS功能
spring-boot-starter-security用Spring Security进行身份验证和授权
spring-boot-starter-data-rest用Spring Data REST公布简单的REST服务

使用Starter

如果想使用Spring的JPA操作数据库,则需要在项目中添加spring-boot-starter-data-jpa依赖,配置如下:

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

如果依赖项目没有版本号,则SpringBoot会根据自己的版本号自动关联。如果需要特定的版本,则需要加上version标签.

 类似资料: