简体   繁体   English

访问spring启动应用程序.properties中提到的配置文件,在创建.jar后用于App引擎部署

[英]Access configuration file mentioned in spring boot application.properties after creating the .jar for App engine deployment

I am facing big trouble in deploying a spring boot application in GCP AppEngine with cloud Postgres as a database.在使用云 Postgres 作为数据库的 GCP AppEngine 中部署 spring 启动应用程序时,我遇到了很大的麻烦。 Earlier I was using tcp connection jdbc with IP whitelisting to access the database, which worked fine during testing but after deploying into Appengine it didn't warmed up due to sslsocket timed out .早些时候,我使用 tcp 连接 jdbc 和 IP 白名单来访问数据库,这在测试期间工作正常,但在部署到sslsocket timed out后它没有预热。 So after a bit of digging, I found for standard appengine runtime to connect a cloud Postgres I have to use postgres socket factory因此,经过一番挖掘,我发现标准的 appengine 运行时要连接云 Postgres 我必须使用 postgres 套接字工厂

        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>postgres-socket-factory</artifactId>
            <version>1.2.2</version>
        </dependency>

with spring.datasource.url=jdbc:postgresql:///{REDACT}?cloudSqlInstance={REDACT}&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user={REDACT}&password={REDACT} in application.properties. with spring.datasource.url=jdbc:postgresql:///{REDACT}?cloudSqlInstance={REDACT}&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user={REDACT}&password={REDACT} in application.properties.

But GCP needs to verify the connection from the key generated from the service account with specific privileges which has been added to the application.properties.但是 GCP 需要使用已添加到 application.properties 的具有特定权限的服务帐户生成的密钥来验证连接。 spring.cloud.gcp.credentials.location=classpath:gcloud.json

But in java the built jar file can't access the json, nor the deployed appengine instance.但是在 java 中,构建的 jar 文件无法访问 json,也无法访问部署的 appengine 实例。 Here's the error这是错误

[Screenshot error in App engine][1] [应用引擎中的屏幕截图错误][1]

app.yaml app.yaml

runtime: java11

pom.xml pom.xml

<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
            <version>1.2.7.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.19</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>postgres-socket-factory</artifactId>
            <version>1.2.2</version>
        </dependency>

Any reply would be of great help.任何回复都会有很大帮助。 Thanks [1]: https://i.stack.imgur.com/gEV2r.png谢谢[1]: https://i.stack.imgur.com/gEV2r.png

With App Engine you don't need to use a service account key file.使用 App Engine,您无需使用服务帐户密钥文件。 You can rely on the metadata server that provides automatically App Engine service account credential.您可以依赖自动提供 App Engine 服务帐户凭据的元数据服务器 Service account is not customizable for now, but should change in 2021: It name is the following: <projectID>@appspot.gserviceaccount.com服务帐户目前不可自定义,但应在 2021 年更改:其名称如下: <projectID>@appspot.gserviceaccount.com

Be sure that this service account has enough Cloud SQL permissions (by default, it has Editor role on the project, and have enough (and even too much!!) permissions)确保此服务帐户具有 足够的 Cloud SQL 权限(默认情况下,它对项目具有 Editor 角色,并且具有足够(甚至太多!!)权限)

So, use the Cloud SQL App Engine connector in the app.yaml file to set up the connection with Cloud SQL and open a socket (to connect with socket factory) in your code因此,请使用app.yaml文件中的 Cloud SQL App Engine 连接器来设置与 Cloud SQL 的连接并在您的代码中打开一个套接字(使用您的代码连接)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 引导应用程序。导出到 jar 后找不到属性 - Spring Boot application.properties not found after exporting to jar 部署后无法访问Google App Engine中的Spring Boot应用程序 - Unable to access Spring Boot application in Google App Engine after deployment 来自application.properties的Spring Boot配置 - Spring Boot configuration from application.properties 如何在 Spring Boot 中访问 application.properties 文件中定义的值 - How to access a value defined in the application.properties file in Spring Boot 在 Spring Boot 中访问 application.properties 文件中定义的值时出现问题 - problem access a value defined in the application.properties file in Spring Boot 如何在 spring web 应用程序中找到 application.properties,虽然位置被提及为 classpath:/application.properties 但文件丢失? - How to find the application.properties in spring web app, while location is mentioned as classpath:/application.properties but file is missing? 如何使用主要方法访问Spring Boot应用程序中application.properties文件中的值 - How to access a value in the application.properties file in Spring Boot app with main method Spring boot application.properties 文件读取 - Spring boot application.properties file reading Spring 引导无法识别 application.properties 文件 - Spring Boot not recognizing application.properties file 如何在 Spring Boot 应用程序的 application.properties 文件中设置 MyBatis 配置属性? - How do I set MyBatis configuration properties in an application.properties file in a Spring Boot application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM