gpt4 book ai didi

java - Spring 启动+gcloud+ "502 Bad Gateway"

转载 作者:行者123 更新时间:2023-12-02 09:12:28 25 4
gpt4 key购买 nike

我正在尝试在 gcloud 上部署此项目: https://github.com/ITger/PolishAPI_sample在本地工作正常,但在 gcloud 上我总是收到 502 错误。

mvn clean package appengine:deploy 命令运行没有问题。

日志(gcloud 应用程序日志尾部)中没有错误,只有信息和调试消息。一周以来,我一直在寻找解决方案并尝试在互联网上找到的许多建议,我遵循了 google、dzone 等教程,但没有运气。

感谢您的帮助

已编辑(回复约翰·汉利):ad 1: 我的代码超过165个java文件,那么如何显示呢???

广告 2:app.yaml:

runtime: java
env: flex
instance_class: F2
runtime_config:
jdk: openjdk8
#env_variables:
# SPRING_PROFILES_ACTIVE: "gcp"
handlers:
- url: /.*
script: this field is required, but ignored
readiness_check:
check_interval_sec: 15
timeout_sec: 14
failure_threshold: 2
success_threshold: 2
app_start_timeout_sec: 1200

广告 3:正如我所说,日志中没有错误,仅包含 spring 信息和调试消息。

application.properties 文件:

debug=true
spring.application.name=polish-api-psd2
springfox.documentation.swagger.v2.path=/api-docs
server.port=${port:8080}
spring.jackson.date-format=pl.itger.PolishAPI.RFC3339DateFormat
#Mongo Config
spring.data.mongodb.database=PolishAPI
spring.data.mongodb.uri=mongodb+srv://polishapi-user:SECRET CLUSTER DATA
spring.data.mongodb.auto-index-creation=true
log4j.category.org.springframework.data.mongodb=DEBUG
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
logging.level.pl.itger=DEBUG
logging.level.root=WARN

App Engine 防火墙规则:

Priority 
1000
Action on match
Allow
IP range
0.0.0.0/0

当我在 Google Cloud Shell 控制台中运行“**mvn clean spring-boot:run -P cloud-gcp**”时,应用程序启动正常,在 Web 预览中应用程序启动与预定义的 swagger ui 页面配合良好:

https://8080-dot-10127310-dot-devshell.appspot.com/

显示所有模型和 API。当我在浏览器中调用“https://8080-dot-10127310-dot-devshell.appspot.com/api-docs”时,效果也很好。使用curl 调用该URL 上的任何休息服务都会导致“访问被禁止”。

但是,在mvn -DskipTests package appengine:deploy -P cloud-gcp之后没有任何效果,只有502 Bad Gateway

[INFO] GCLOUD: Setting traffic split for service [default]...
[INFO] GCLOUD: ..............................................................done.
[INFO] GCLOUD: Deployed service [default] to [https://polish-api-psd2.appspot.com]
[INFO] GCLOUD:
[INFO] GCLOUD: You can stream logs from the command line by running:
[INFO] GCLOUD: $ gcloud app logs tail -s default
[INFO] GCLOUD:
[INFO] GCLOUD: To view your application in the web browser run:
[INFO] GCLOUD: $ gcloud app browse
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 09:15 min
[INFO] Finished at: 2019-12-12T15:49:39+01:00
[INFO] ------------------------------------------------------------------------
p_zerynger@cloudshell:~/PolishAPI_sample/server (polish-api-psd2)$

完整日志(它很短,与“mvn spring-boot:run -P cloud-gcp”之后的不同,我不知道为什么):

ar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-data-jpa-2.1.10.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-orm-5.2.2.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/spring-jdbc-5.2.2.RELEASE.jar!/, jar:file:/app.jar!/BOOT-INF/lib/aspectjrt-1.9.5.jar!/, jar:file:/app.jar!/BOOT-INF/lib/lombok-1.18.10.jar!/, jar:file:/app.jar!/BOOT-INF/lib/core-1.5.3.jar!/, jar:file:/app.jar!/BOOT-INF/lib/proxytoys-1.0.jar!/, jar:file:/app.jar!/BOOT-INF/lib/gson-2.8.6.jar!/, jar:file:/app.jar!/BOOT-INF/lib/annotations-17.0.0.jar!/, jar:file:/app.jar!/BOOT-INF/lib/jaxb-api-2.3.1.jar!/, jar:file:/app.jar!/BOOT-INF/lib/javax.activation-api-1.2.0.jar!/]
2019-12-12 14:48:53 default[1]
2019-12-12 14:48:53 default[1] . ____ _ __ _ _
2019-12-12 14:48:53 default[1] /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
2019-12-12 14:48:53 default[1] ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2019-12-12 14:48:53 default[1] \\/ ___)| |_)| | | | | || (_| | ) ) ) )
2019-12-12 14:48:53 default[1] ' |____| .__|_| |_|_| |_\__, | / / / /
2019-12-12 14:48:53 default[1] =========|_|==============|___/=/_/_/_/
2019-12-12 14:48:53 default[1] :: Spring Boot :: (v2.2.2.RELEASE)
2019-12-12 14:48:53 default[1]
2019-12-12 14:48:54 default[1] 2019-12-12 14:48:54.093 INFO 1 --- [ main] p.i.P.PolishAPI_2_1_2_SpringBoot : Starting PolishAPI_2_1_2_SpringBoot v1.0.1 on e1b35acb6032 with PID 1 (/app.jar started by root in /)
2019-12-12 14:48:54 default[1] 2019-12-12 14:48:54.096 DEBUG 1 --- [ main] p.i.P.PolishAPI_2_1_2_SpringBoot : Running with Spring Boot v2.2.2.RELEASE, Spring v5.2.2.RELEASE
2019-12-12 14:48:54 default[1] 2019-12-12 14:48:54.098 INFO 1 --- [ main] p.i.P.PolishAPI_2_1_2_SpringBoot : No active profile set, falling back to default profiles: default
2019-12-12 14:48:54 default[1] 2019-12-12 14:48:54.102 DEBUG 1 --- [ main] o.s.boot.SpringApplication : Loading source class pl.itger.PolishAPI.PolishAPI_2_1_2_SpringBoot
2019-12-12 14:48:54 default[1] 2019-12-12 14:48:54.341 DEBUG 1 --- [ main] o.s.b.c.c.ConfigFileApplicationListener : Loaded config file 'jar:file:/app.jar!/BOOT-INF/classes!/application.properties' (classpath:/application.properties)
2019-12-12 14:48:54 default[1] 2019-12-12 14:48:54.345 DEBUG 1 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@6c3708b3
2019-12-12 14:52:42 default[1] I1212 14:51:56.693214 26 callbacks_monitor.cc:66] Cloud Debugger call "JVMTI:ClassPrepare" completed after 25847 ms

++++++++++在云http负载均衡器日志中我发现了这个:

jsonPayload: {
@type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"
statusDetails: "failed_to_connect_to_backend"
}

It's crazy... now timeout:

[INFO] GCLOUD: ERROR: (gcloud.app.deploy) Error Response: [4] App Engine Flexible timed out while configuring resources, internal operation projects/polish-api-psd2/regions/europe-west1/operations/3343fc51-2991-4da1-ba45-128bd897d92f

最佳答案

每个部署都分配有一个版本号。验证该版本号是否出现在“app engine”下的“版本”部分中您的 GCP 项目。如果版本号确实出现,StackDriver 中将提供日志,详细说明发生的任何可能的部署错误。

如果版本号没有出现,则重新部署项目,这次启用详细标志以生成部署日志。[1]

最后,尝试部署一个最低限度的“Hello World”应用程序,看看如果问题与代码无关的话是否有效。

[1] https://cloud.google.com/sdk/gcloud/reference/#--verbosity

关于java - Spring 启动+gcloud+ "502 Bad Gateway",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59295155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com