6、(2.5分)Spring Boot中的核心模块是什么 A、 spring-boot-starter B、 spring-boot-actuator C、spring-boot-autoconfigure D、 spring-boot-cli
时间: 2024-01-28 09:05:16 浏览: 102
A、spring-boot-starter。spring-boot-starter是Spring Boot中的核心模块,它提供了一系列的starter,可以方便地引入常用的依赖。例如,要使用Spring MVC,可以引入spring-boot-starter-web;要使用JPA,可以引入spring-boot-starter-data-jpa等。spring-boot-starter的设计思想是约定大于配置,通过提供常用的starter,使得开发者可以快速地构建应用程序。spring-boot-actuator提供了应用程序的监控和管理功能,spring-boot-autoconfigure提供了自动配置功能,spring-boot-cli是Spring Boot的命令行工具。
相关问题
spring-boot-starter-actuator
Spring Boot Actuator is a sub-project of Spring Boot that provides a set of production-ready features to help you monitor and manage your application when it's deployed in production. The spring-boot-starter-actuator dependency provides all the necessary dependencies to use the Actuator features in your Spring Boot application, such as:
1. Health checks: Provides information about the health of your application.
2. Metrics: Provides information about various metrics such as CPU usage, memory usage, request counts, etc.
3. Auditing: Provides information about the activity of your application such as who accessed a specific endpoint and when.
4. Tracing: Provides information about the requests and their flow through your application.
5. Management: Provides endpoints to manage your application, such as shutting it down or restarting it.
By including the spring-boot-starter-actuator dependency in your project, you can easily enable and configure these Actuator features in your application.
spring-boot-starter-actuator 示例
spring-boot-starter-actuator是Spring Boot提供的一个模块,它提供了一系列的端点(endpoints)用于监控和管理Spring Boot应用。
下面是一个spring-boot-starter-actuator示例:
首先,需要在pom.xml文件中添加spring-boot-starter-actuator依赖:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
```
然后,在application.properties或application.yml中配置端点的访问路径:
```yaml
management.endpoints.web.base-path=/actuator
```
其中,/actuator是端点的访问路径。
接下来,可以访问以下端点:
- /actuator/health:应用健康状况检查
- /actuator/info:应用信息
- /actuator/metrics:应用指标信息
- /actuator/loggers:日志配置信息
- /actuator/mappings:请求URL映射信息
例如,可以访问http://localhost:8080/actuator/health查看应用的健康状况。
需要注意的是,开启端点后,可能会存在安全风险,因此需要对端点进行安全配置。可以通过以下配置关闭所有端点的访问:
```yaml
management.endpoints.enabled-by-default=false
```
然后,通过以下配置开启需要的端点:
```yaml
management.endpoint.health.enabled=true
management.endpoint.info.enabled=true
```
以上配置开启了/actuator/health和/actuator/info端点的访问。
阅读全文