我正在尝试为我的 Java 应用程序配置 Google App Engine 灵活环境,并且我想使用 Java 11 作为运行时。但是,我遇到了一个问题,它似乎正在使用 Java 8,并且出现以下错误:
google_app_engine_flexible_app_version.myapp_v1: Still creating... [3m30s elapsed]╷│ Error: Error waiting to create FlexibleAppVersion: Error waiting for Creating FlexibleAppVersion: Error code 9, message: An internal error occurred while processing task /app-engine-flex/flex_await_healthy/flex_await_healthy>2023-10-27T03:35:51.497Z43727.vt.2: Start command: java -showversion -Xms491M -Xmx491M -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -jar app.jar
│ -XX:InitialHeapSize=514850816 -XX:MaxHeapSize=514850816 -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC
│ openjdk version "1.8.0_345"
│ OpenJDK Runtime Environment (Temurin)(build 1.8.0_345-b01)
│ OpenJDK 64-Bit Server VM (Temurin)(build 25.345-b01, mixed mode)
│ │ Error: A JNI error has occurred, please check your installation and try again
│ Exception in thread "main" java.lang.UnsupportedClassVersionError: com/example/appengine/Application has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
│ at java.lang.ClassLoader.defineClass1(Native Method)
│ at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
│ at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
│ at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
│ at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
│ at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
│ at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
│ at java.security.AccessController.doPrivileged(Native Method)
│ at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
│ at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
│ at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
│ at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
│ at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
我已经像这样配置了我的 google_app_engine_flexible_app_version 资源:这次我尝试使用 terraform 资源中的 app.yaml 文件
resource "google_app_engine_flexible_app_version" "myapp_v1" {
version_id = "v1"
project = "fresh-test1"
service = "servcie1"
runtime = "java"
deployment {
files {
name = "micronaut-helloworld-0.1.jar"
source_url = "https://storage.googleapis.com/${google_storage_bucket.bucket.name}/${google_storage_bucket_object.object.name}"
}
cloud_build_options {
app_yaml_path = "[./app.yaml]"
}
}
liveness_check {
path = "/"
}
readiness_check {
path = "/"
}
env_variables = {
port = "8080"
}
automatic_scaling {
cool_down_period = "120s"
max_total_instances = 2
min_total_instances = 1
cpu_utilization {
target_utilization = 0.5
}
}
delete_service_on_destroy = true
service_account = google_service_account.custom_service_account.email
}
app.yaml
runtime: java
env: flex
runtime_config:
operating_system: ubuntu22
runtime_version: 11
service: api
handlers:
- url: /.*
script: this field is required, but ignored
resources:
cpu: 1
memory_gb: 4
disk_size_gb: 40
automatic_scaling:
min_num_instances: 1
max_num_instances: 1
cpu_utilization:
target_utilization: 0.85
env_variables:
SPRING_PROFILES_ACTIVE: prod
我正在从 google cloud shell 运行 terraform 代码。 和 Java --version 指向 java17 JAVA_HOME指向java11 我不知道这是否重要。
有没有办法正确配置 Google App Engine 灵活环境以使用 Java 11 作为运行时?我是否使用了正确的入口点和运行时配置?任何帮助或指导将不胜感激。
我也有同样的错误。
我有一个 Spring Boot 应用程序,我将项目从 Java 8 迁移到 Java 17,我可以在 10 月 14 日正常部署。我可以在日志中看到该应用程序正在 Java 17 上运行。
10 月 15 日,我只是添加了一个小功能,没有更改配置,然后我开始遇到同样的错误。
由于我没有更改配置,我认为这是 Google Cloud 上的问题,但自 10 月 15 日以来,这种情况一直在我身上发生。
这是我的 app.yaml,是按照 Google Cloud 教程制作的:
runtime: java
env: flex
runtime_config:
operating_system: ubuntu22
runtime_version: 17
service: api
handlers:
- url: /.*
script: this field is required, but ignored
resources:
cpu: 1
memory_gb: 4
disk_size_gb: 40
automatic_scaling:
min_num_instances: 1
max_num_instances: 1
cpu_utilization:
target_utilization: 0.85
env_variables:
SPRING_PROFILES_ACTIVE: prod