Spring Boot Actuator干扰HTTPS请求问题排查与解决
问题描述
我在使用spring-boot-starter-actuator给服务添加健康检查端点时遇到问题:添加该依赖后服务无法接收请求,移除依赖后服务恢复正常。请问该如何解决?
错误现象
Swagger调用服务时的错误:

Postman调用时的错误:

依赖信息
Actuator依赖树
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.5.10:compile [INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.5.10:compile [INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.10:compile [INFO] | | | | \- ch.qos.logback:logback-core:jar:1.2.10:compile [INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.1:compile [INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile [INFO] | | \- org.yaml:snakeyaml:jar:1.28:compile [INFO] | +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:2.5.10:compile [INFO] | | +- org.springframework.boot:spring-boot-actuator:jar:2.5.10:compile [INFO] | | \- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.6:compile [INFO] | \- io.micrometer:micrometer-core:jar:1.7.9:compile [INFO] | +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile [INFO] | \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
我的Actuator依赖配置
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
注意:项目未引入Spring Security,Spring Boot版本为2.5.10
解决方案
1. 调整Actuator端点暴露配置
Spring Boot 2.x中Actuator默认仅暴露health和info端点,若存在路径冲突或需确保业务端点正常访问,可添加以下配置:
# 按需暴露Actuator端点(*表示全部暴露) management.endpoints.web.exposure.include=* # 自定义Actuator基础路径,避免与业务接口冲突 management.endpoints.web.base-path=/actuator
2. 排查Web容器启动异常
查看服务启动日志,重点关注ERROR或WARN级别的信息,确认Tomcat/Jetty等Web容器是否正常启动、端口是否被占用。Actuator依赖引入的组件可能导致容器初始化失败,日志会给出具体原因。
3. 解决Jackson版本冲突
Actuator引入了jackson-datatype-jsr310,若项目中存在其他版本的Jackson依赖,易引发冲突。执行mvn dependency:tree查看Jackson相关依赖,统一版本:
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.12.6</version> <!-- 与Actuator引入的版本保持一致 --> </dependency>
4. 禁用不必要的Actuator自动配置
若部分Actuator自动配置类影响服务启动,可在启动类中排除:
@SpringBootApplication(exclude = {ActuatorAutoConfiguration.class, HealthIndicatorAutoConfiguration.class}) public class YourApplication { public static void main(String[] args) { SpringApplication.run(YourApplication.class, args); } }
5. 检查服务上下文路径配置
若项目设置了server.servlet.context-path,需确保Actuator的management.endpoints.web.base-path不与业务路径重叠,同时业务请求需正确包含上下文路径。
内容的提问来源于stack exchange,提问作者Carlos Mario
相关产品推荐
相关产品推荐

