[英]@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 Boot 應用程序在端口 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/
,那么它只會恢復為/
。 我已經嘗試了很多次,甚至嘗試刪除它並創建一個新的。 沒有。 所以我放棄了。 相反,我想,我只會創建路徑/
返回健康檢查的狀態代碼。
所以我做了這個:
@GetMapping("/")
public ResponseEntity<String> dummyMethod() {
return new ResponseEntity<>("Hello from Dummy-Root-Method", HttpStatus.OK);
}
認為現在當健康檢查被調用時,它會成功,但這也不起作用。 如果我在本地運行服務器,我可以訪問/
端點,但是當它在 Elastic Beanstalk 中時,它認為該路徑不存在。 但是,我的其他端點確實可以工作。 這是工作端點 (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 環境中?我只是希望我的環境不是紅色的。 它工作正常,但有健康檢查錯誤。
驗證 Beanstalk 是否正在運行最新版本的代碼。 可能仍在使用添加新映射之前啟動的容器。
問題是,即使我通過 EBS CLI 部署了一個新版本,它實際上並沒有部署我的最新更改。 如果您在項目中設置了 git,那么它只會部署最后一次提交。 所以我不得不提交我的更改,然后重新部署它並工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.