【发布时间】:2019-08-23 11:54:39
【问题描述】:
我正在尝试将我的 App Engine 应用程序(在 Java Spring Boot 中)与 Cloud SQL 数据库连接。部署工作正常,应用启动,但连接到 Cloud SQL 受阻:
main] c.g.cloud.sql.core.CoreSocketFactory : First Cloud SQL connection, generating RSA key pair.
main] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [test-api:europe-west1:test-db] via SSL socket.
// Nothing happens after that !
我该怎么做?
1) 我使用用户名和密码在我的数据库上创建了一个用户(例如 postgres 和 postgres)。
2) 我将此依赖项添加到我的项目中
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
<version>1.1.2.RELEASE</version>
</dependency>
3) 我用
更新 application.properties# Gcp configuration
spring.cloud.gcp.sql.database-name=test
spring.cloud.gcp.sql.instance-connection-name=test-api:europe-west1:test-db
#Jdbc connection
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.datasource.url=jdbc:postgresql://google/test?cloudSqlInstance=test-api:europe-west1:test-db&socketFactory=com.google.cloud.sql.postgres.SocketFactory&useSSL=false&user=postgres&password=postgres
有什么问题?
问题是在Connecting to Cloud SQL instance 日志之后没有任何反应。 (见前)
在启动日志中我可以看到这些信息:
main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.19]
main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 11980 ms
main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Default POSTGRESQL JdbcUrl provider. Connecting to jdbc:postgresql://google/test?socketFactory=com.google.cloud.sql.postgres.SocketFactory&socketFactoryArg=test-api:europe-west1:test-db&useSSL=false with driver org.postgresql.Driver
main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : spring.datasource.url is specified. Not using generated Cloud SQL configuration
main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
main] c.g.cloud.sql.core.CoreSocketFactory : First Cloud SQL connection, generating RSA key pair.
main] c.g.cloud.sql.core.CoreSocketFactory : Connecting to Cloud SQL instance [test-api:europe-west1:test-db] via SSL socket.
另一个奇怪的点是我指定&useSSL=false,但应用程序根据日志连接via SSL socket。
【问题讨论】:
-
您是否正在尝试遵循类似 cloud.google.com/sql/docs/postgres/connect-app-engine 的一些 Google 文档?您使用的是 App Engine Flex 还是 Standard?如果您使用的是 fexible,我认为本教程对您有用cloud.google.com/community/tutorials/…。
标签: spring google-app-engine jdbc google-cloud-platform google-cloud-sql