You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GCP App Engine部署后无法读取CloudSQL密钥,本地运行正常求助

App Engine部署SpringBoot应用后无法读取Cloud SQL凭证文件

我将Java SpringBoot应用部署在GCP的App Engine上,通过Cloud Build从Github仓库拉取代码部署。仓库文件结构如下:

server
   \src\main
            \appengine
               \app.yaml
            \java
            \resources
               \service-account-key.json
   \cloudbuild.yaml
   \pom.xml
client

仅部署server部分,client部分被忽略。本地开发环境运行正常,能正常连接并操作CloudSQL,但部署到App Engine后,虽然部署成功,但访问应用URL时出现以下错误:

java.lang.IllegalArgumentException: Error reading Cloud SQL credentials file: class path resource [service-account-key.json]. Please verify the specified file path.

相关配置

application.properties中的相关配置:
spring.cloud.gcp.credentials.location=classpath:/service-account-key.json

app.yaml内容:

runtime: java17
instance_class: F1

cloudbuild.yaml内容:

steps:
  - id: 'Stage app using mvn appengine plugin on mvn cloud build image'
    name: 'gcr.io/cloud-builders/mvn'
    dir: 'server'
    args: ['package', 'appengine:stage']
  - id: 'Deploy to app engine using gcloud image'
    name: 'gcr.io/cloud-builders/gcloud'
    dir: 'server'
    args: ['app', 'deploy', 'target/appengine-staging/app.yaml']
timeout: "1600s"

已尝试的解决方法

我试过以下方法,但都没能解决问题:

  • 跳过Cloud Build手动部署
  • 修改app.yaml添加静态URL处理器(可能语法有误)
  • 将密钥文件从resources/目录移到server/目录
  • 用file:替代配置中的classpath:
  • 指定完整路径,比如src/main/resources/service-account-key.json和server/src/main/resources/service-account-key.json

请问故障原因可能是什么?

内容的提问来源于stack exchange,提问作者dense8

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 09:32:11