You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在pom.xml中正确排除spring-boot-starter-actuator?排除后健康信息仍显示

解决Spring Boot健康端点仍可见的问题

首先,我注意到你在spring-boot-maven-plugin的排除配置里有个容易忽略的小错误:<artifactId>spring-boot-starter-actuator </artifactId>的末尾多了一个空格,这会导致Maven无法匹配到正确的依赖,所以你的排除操作根本没生效。先把这个空格去掉,这是最优先要修正的点。

不过就算修正了空格,插件层面的排除也只是在打包阶段移除依赖——如果你的项目中其他依赖(比如某个starter)间接引入了spring-boot-starter-actuator,它依然会出现在依赖树里,导致健康端点能正常访问。更稳妥的做法是从依赖声明层面直接排除它:

方案1:在依赖源中排除Actuator

找到项目中引入spring-boot-starter-actuator的那个依赖(比如spring-boot-starter-web或者自定义starter),在该依赖下添加排除规则:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <!-- 排除间接引入的actuator依赖 -->
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </exclusion>
    </exclusions>
</dependency>

方案2:用依赖树定位来源

如果你不确定哪个依赖偷偷引入了Actuator,可以执行Maven命令查看完整依赖树:

mvn dependency:tree | grep actuator

这个命令会帮你揪出所有包含actuator的依赖路径,然后针对对应的父依赖添加排除即可。

方案3:无法移除依赖时直接禁用端点

如果因为某些原因没办法完全移除Actuator依赖,也可以在配置文件(比如application.properties或application.yml)里彻底禁用健康端点:

# 关闭所有actuator端点
management.endpoints.enabled-by-default=false
# 或者仅单独关闭健康端点
management.endpoint.health.enabled=false

最后记得执行mvn clean package重新打包项目,确保所有修改都能生效。

内容的提问来源于stack exchange,提问作者maskipaps

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:27:23