Spring Boot学习3 - Spring Boot启动器(Spring Boot Starters)

叶国兴
2023-12-01

Spring Boot启动器(Spring Boot Starters)

处理各类库的依赖管理对于大型项目来说是一项艰巨的任务,Spring Boot通过提供一组依赖项来解决此问题,以方便开发人员。
例如,如果要使用Spring和JPA进行数据库访问,则在项目中包含spring-boot-starter-data-jpa依赖项就够了。
所有Spring Boot启动器都遵循相同的命名模式spring-boot-starter- ,其中表示它是应用程序的一种类型。


例子

请看下面的Spring Boot启动器,以便更好地理解 -

Spring Boot Starter Actuator

此依赖项用于监视和管理您的应用程序。其代码如下所示

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

Spring Boot Starter Security

此依赖项用于Spring 安全相关工作。其代码如下所示

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

Spring Boot Starter Web

此依赖关系用于编写Rest端点。其代码如下所示 -

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

Spring Boot Starter Thyme Leaf

此依赖项用于创建Web应用程序。其代码如下所示

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

Spring Boot Starter Test

此依赖项用于编写测试用例。其代码如下所示

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test<artifactId>
</dependency>
 类似资料: