Spring Boot Actuator访问/health与/mappings出现白标错误页问题
解决Spring Boot Actuator端点出现Whitelabel Error Page的问题
嘿,我来帮你搞定这个问题!你遇到的情况在Spring Boot初学者里挺常见的,咱们一步步拆解排查:
1. 先确认是否引入了Actuator依赖
STS创建的极简Spring Boot项目默认不会包含Actuator依赖,这大概率是问题的核心原因。你需要在项目的依赖管理文件里手动添加:
Maven 项目(修改pom.xml):
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
Gradle 项目(修改build.gradle):
implementation 'org.springframework.boot:spring-boot-starter-actuator'
添加完依赖后记得重启项目,这是后续配置生效的基础。
2. 配置Actuator端点的暴露规则
从Spring Boot 2.x版本开始,Actuator默认只对外暴露/health这一个端点,而且还是简化版的信息;像/mappings这类端点默认是隐藏状态的。你需要在配置文件里调整暴露规则:
用application.properties配置:
# 按需暴露端点,*代表暴露所有,也可以指定具体端点比如health,mappings management.endpoints.web.exposure.include=* # 如果需要查看health的详细状态信息,加上这行 management.endpoint.health.show-details=always
用application.yml配置:
management: endpoints: web: exposure: include: '*' # 或者指定具体端点:health,mappings endpoint: health: show-details: always
3. 注意端点访问路径的变化
这里有个很容易踩的坑:Spring Boot 2.x之后,Actuator的所有端点默认都挂载在/actuator路径下,不再是旧版本(1.x)的根路径!你之前访问的http://localhost:8080/health和http://localhost:8080/mappings是错误路径,正确的访问地址应该是:
http://localhost:8080/actuator/healthhttp://localhost:8080/actuator/mappings
至于日志没报错,是因为这些端点根本没被注册到应用中,系统只是返回了404状态,没有触发异常日志。
按照上面的步骤操作后,应该就能正常访问这两个Actuator端点了。如果还有问题,可以核对下你的Spring Boot版本,确保配置属性和版本匹配(2.x和3.x配置基本一致,1.x差异较大)。
内容的提问来源于stack exchange,提问作者osama yaccoub
相关产品推荐
相关产品推荐

