@GetMapping("/") 在 Elastic Beanstalk 中不起作用,但在本地起作用
@GetMapping("/") does not work in Elastic Beanstalk but works locally
我的 Elastic Beanstalk 环境的运行状况为 severe
。我相信这是因为我没有处理健康检查。这可以在我的日志中看到:
/var/log/nginx/access.log
----------------------------------------
172.31.75.161 - - [08/Nov/2021:13:21:41 +0000] "GET / HTTP/1.1" 404 116 "-" "ELB-HealthChecker/2.0" "-"
172.31.75.161 - - [08/Nov/2021:13:21:41 +0000] "GET / HTTP/1.1" 404 116 "-" "ELB-HealthChecker/2.0" "-"
...
43 connect() failed (111: Connection refused) while connecting to upstream, client: 172.XX.XX.XX, server: , request: "GET / HTTP/1.1", upstream: "http://172.XX.XX.XX:8080/"
这是我的 Docker 文件:
# Build stage
#
FROM maven:3.8.1-jdk-8
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package
#
# Package stage
#
FROM openjdk:8
COPY --from=0 /tmp/target/para-host-0.0.1-SNAPSHOT.jar /usr/local/lib/para.jar
EXPOSE 5000
ENTRYPOINT ["java","-jar","/usr/local/lib/para.jar"]
所以我的 Spring 启动应用程序 运行s 在端口 5000 上。这在本地和 Elastic Beanstalk 中都有效。
到目前为止我尝试了什么
我尝试使用此依赖项来添加健康检查功能:
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
在那之后,我能够 运行 本地服务器并像这样访问端点:
http://localhost:5000/actuator/health
并得到响应:
{
"status": "UP"
}
(这是状态码吗?)
这是它坏掉的地方
在我的 Elastic Beanstalk 环境中的负载均衡器中,它说我的健康检查路径是 /
。如果我将该值编辑为 /actuator/health/
,则它会恢复为 /
。我试过很多次,甚至尝试删除它并创建一个新的。没有什么。所以我放弃了。相反,我想,我只会将路径 /
return 作为健康检查的状态代码。
所以我做了这个:
@GetMapping("/")
public ResponseEntity<String> dummyMethod() {
return new ResponseEntity<>("Hello from Dummy-Root-Method", HttpStatus.OK);
}
认为现在调用健康检查时会成功,但这也行不通。如果我在本地 运行 服务器,我可以访问 /
端点,但是当它在 Elastic Beanstalk 中时,它认为路径不存在。但是,我的其他端点 DO 工作。这是工作端点 (getGroupResults) 和非工作端点 (dummyMethod) 的片段:
@GetMapping("/get-group-results")
public ResponseEntity<String> getGroupResults(@RequestBody ObjectNode objectNode)
throws IOException, AddressException, MessagingException {
String groupFolder = objectNode.get("group").asText();
String sendToEmail = objectNode.get("email").asText();
logger.info("Attempting to get results from folder: {}", groupFolder);
String attachmentPath = Test.getMapFromGroupFolder(groupFolder).getAbsolutePath();
String subject = "Results from parallenium";
MailService.sendEmailWithAttachment(sendToEmail, attachmentPath, subject);
return new ResponseEntity<>("Successfully sent results email", HttpStatus.OK);
}
/**
* Dummy response for ELB so we do not receive errors
*
* @return
*/
@GetMapping("/")
public ResponseEntity<String> dummyMethod() {
return new ResponseEntity<>("Hello from Dummy-Root-Method", HttpStatus.OK);
}
这是我在 Elastic Beanstalk 中尝试访问 /actuator/health/
端点时得到的响应 http://para-server.us-east-1.elasticbeanstalk.com/actuator/health
:
{
"timestamp": "2021-11-08T16:56:20.785+00:00",
"status": 404,
"error": "Not Found",
"path": "/"
}
同样,这在本地有效。为什么?
总结。我能做什么?
- 为什么我不能更改 Elastic Beanstalk 控制台中健康检查的路径?
- 为什么根路径
/
在本地有效,但在我的 Elastic Beanstalk 环境中无效?
我只是希望我的环境不显示为红色。它工作正常,但有健康检查错误。
验证 Beanstalk 是 运行 您代码的最新版本。在您添加新映射之前,可能仍在使用启动的容器。
问题是,即使我通过 EBS CLI 部署新版本,它实际上并没有部署我的最新更改。如果您在项目中设置了 git,那么它只会部署最后一次提交。所以我不得不提交我的更改,然后重新部署它并开始工作。
我的 Elastic Beanstalk 环境的运行状况为 severe
。我相信这是因为我没有处理健康检查。这可以在我的日志中看到:
/var/log/nginx/access.log
----------------------------------------
172.31.75.161 - - [08/Nov/2021:13:21:41 +0000] "GET / HTTP/1.1" 404 116 "-" "ELB-HealthChecker/2.0" "-"
172.31.75.161 - - [08/Nov/2021:13:21:41 +0000] "GET / HTTP/1.1" 404 116 "-" "ELB-HealthChecker/2.0" "-"
...
43 connect() failed (111: Connection refused) while connecting to upstream, client: 172.XX.XX.XX, server: , request: "GET / HTTP/1.1", upstream: "http://172.XX.XX.XX:8080/"
这是我的 Docker 文件:
# Build stage
#
FROM maven:3.8.1-jdk-8
ADD src /tmp/src
ADD pom.xml /tmp/pom.xml
RUN mvn -f /tmp/pom.xml clean package
#
# Package stage
#
FROM openjdk:8
COPY --from=0 /tmp/target/para-host-0.0.1-SNAPSHOT.jar /usr/local/lib/para.jar
EXPOSE 5000
ENTRYPOINT ["java","-jar","/usr/local/lib/para.jar"]
所以我的 Spring 启动应用程序 运行s 在端口 5000 上。这在本地和 Elastic Beanstalk 中都有效。
到目前为止我尝试了什么 我尝试使用此依赖项来添加健康检查功能:
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
在那之后,我能够 运行 本地服务器并像这样访问端点:
http://localhost:5000/actuator/health
并得到响应:
{
"status": "UP"
}
(这是状态码吗?)
这是它坏掉的地方
在我的 Elastic Beanstalk 环境中的负载均衡器中,它说我的健康检查路径是 /
。如果我将该值编辑为 /actuator/health/
,则它会恢复为 /
。我试过很多次,甚至尝试删除它并创建一个新的。没有什么。所以我放弃了。相反,我想,我只会将路径 /
return 作为健康检查的状态代码。
所以我做了这个:
@GetMapping("/")
public ResponseEntity<String> dummyMethod() {
return new ResponseEntity<>("Hello from Dummy-Root-Method", HttpStatus.OK);
}
认为现在调用健康检查时会成功,但这也行不通。如果我在本地 运行 服务器,我可以访问 /
端点,但是当它在 Elastic Beanstalk 中时,它认为路径不存在。但是,我的其他端点 DO 工作。这是工作端点 (getGroupResults) 和非工作端点 (dummyMethod) 的片段:
@GetMapping("/get-group-results")
public ResponseEntity<String> getGroupResults(@RequestBody ObjectNode objectNode)
throws IOException, AddressException, MessagingException {
String groupFolder = objectNode.get("group").asText();
String sendToEmail = objectNode.get("email").asText();
logger.info("Attempting to get results from folder: {}", groupFolder);
String attachmentPath = Test.getMapFromGroupFolder(groupFolder).getAbsolutePath();
String subject = "Results from parallenium";
MailService.sendEmailWithAttachment(sendToEmail, attachmentPath, subject);
return new ResponseEntity<>("Successfully sent results email", HttpStatus.OK);
}
/**
* Dummy response for ELB so we do not receive errors
*
* @return
*/
@GetMapping("/")
public ResponseEntity<String> dummyMethod() {
return new ResponseEntity<>("Hello from Dummy-Root-Method", HttpStatus.OK);
}
这是我在 Elastic Beanstalk 中尝试访问 /actuator/health/
端点时得到的响应 http://para-server.us-east-1.elasticbeanstalk.com/actuator/health
:
{
"timestamp": "2021-11-08T16:56:20.785+00:00",
"status": 404,
"error": "Not Found",
"path": "/"
}
同样,这在本地有效。为什么?
总结。我能做什么?
- 为什么我不能更改 Elastic Beanstalk 控制台中健康检查的路径?
- 为什么根路径
/
在本地有效,但在我的 Elastic Beanstalk 环境中无效?
我只是希望我的环境不显示为红色。它工作正常,但有健康检查错误。
验证 Beanstalk 是 运行 您代码的最新版本。在您添加新映射之前,可能仍在使用启动的容器。
问题是,即使我通过 EBS CLI 部署新版本,它实际上并没有部署我的最新更改。如果您在项目中设置了 git,那么它只会部署最后一次提交。所以我不得不提交我的更改,然后重新部署它并开始工作。