部署集成Swagger的Spring Boot 3应用至AWS遇严重问题求助
解决AWS Elastic Beanstalk部署Spring Boot 3+Swagger应用的Severe状态问题
Severe
Environment health has transitioned from Ok to Severe. 100.0 % of the requests are erroring with HTTP 4xx. Insufficient request rate (12.0 requests/min) to determine application health. ELB processes are not healthy on all instances. ELB health is failing or not available for all instances.
以下是针对性的排查和解决步骤:
1. 修正ELB健康检查路径
Elastic Beanstalk默认用/作为健康检查路径,如果你的应用根路径没有返回200(比如仅通过/swagger-ui/index.html访问Swagger),ELB会判定实例不健康:
- 进入AWS控制台的Elastic Beanstalk环境,点击配置 > 负载均衡器
- 将健康检查路径改为可返回200的端点:
- 推荐引入Spring Boot Actuator依赖,用
/actuator/health作为健康检查路径(需在配置文件中开启:management.endpoints.web.exposure.include=health) - 临时方案:在Controller中添加根路径响应:
@GetMapping("/") public ResponseEntity<String> healthCheck() { return ResponseEntity.ok("Healthy"); }
- 推荐引入Spring Boot Actuator依赖,用
2. 确认端口配置与流量规则
- 查看EC2实例的完整日志,搜索
Tomcat started on port(s): 5000,确认应用确实监听5000端口 - 检查EC2实例的安全组,入站规则需允许5000端口的流量来自ELB的安全组(或临时设为
0.0.0.0/0测试)
3. 启用生产环境的Swagger
Spring Boot 3配套的SpringDoc Swagger默认在生产环境禁用,需在application.properties中添加:
springdoc.api-docs.enabled=true springdoc.swagger-ui.enabled=true
4. 验证平台兼容性
确保Elastic Beanstalk选择的Java平台版本为Corretto 17+(Spring Boot 3要求Java 17及以上),低版本Java会导致应用启动失败。
内容的提问来源于stack exchange,提问作者Sercan Noyan Germiyanoğlu
相关产品推荐
相关产品推荐

