屏蔽 /actuator
时间: 2023-10-31 11:52:38 浏览: 181
您可以使用Spring Boot的安全配置来屏蔽/actuator端点。这可以通过以下步骤完成:
1. 在您的项目的`pom.xml`文件中,确保包含了`spring-boot-starter-actuator`依赖。如果没有,请添加以下依赖项:
```xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
```
2. 在您的应用程序配置文件(如`application.properties`或`application.yml`)中,设置以下属性,以限制对/actuator端点的访问:
```properties
# 屏蔽所有端点
management.endpoints.web.exposure.exclude=*
# 允许访问指定端点(除了/actuator)
management.endpoints.web.exposure.include=health,info
# 配置访问端点的路径前缀
management.endpoints.web.base-path=/admin
```
或者在`application.yml`文件中:
```yaml
management:
endpoints:
web:
exposure:
exclude: "*"
include: health,info
base-path: /admin
```
在上述示例中,所有端点都被屏蔽了(使用`exclude=*`),只允许访问`health`和`info`端点(使用`include=health,info`)。此外,使用`base-path=/admin`配置了访问端点的路径前缀为`/admin`。
3. 重新启动您的应用程序,现在/actuator端点应该被屏蔽了。
请注意,这只是一种方法来屏蔽/actuator端点,并且还有其他的方法可以达到相同的效果,具体取决于您的应用程序的需求和配置。这里提供的方法是一种常见的做法。
阅读全文
相关推荐















