【发布时间】:2025-12-15 22:55:02
【问题描述】:
我正在尝试将我的数据库从 Google 灵活环境 连接到 Google Cloud SQL。连接字符串和驱动类如下所示:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.GoogleDriver" />
<property name="url" value="jdbc:google:mysql://mz-test:us-central1:mz-life-cloudsql-prod/mz_db" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
但是,我目前正在接受
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/classes/context/applicationContext-jooq.xml]:
Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException;
nested PropertyAccessExceptions (1) are:|PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception;
nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.GoogleDriver]
我尝试连接的数据库是第二代 Cloud SQL MySQL 数据库。
为什么会出现这个异常?
App Engine 有这个<use-google-connector-j> 属性。我还没有看到灵活环境的这个属性——至少在我目前阅读的那些页面上没有。我需要在 app.yaml 文件中添加什么内容吗?
不确定我是否必须在灵活环境中执行此操作,但我目前正在尝试在我的 yaml 文件中将 use-google-connector-j 属性设置为 true:
use-google-connector-j: true
但目前看来这不起作用:https://code.google.com/p/googleappengine/issues/detail?id=11444
【问题讨论】:
-
但是您在问题中添加了两个标签
-
@Jens 那是因为我使用的是 Google Flexible Environment,而这实际上是 Google App Engine 和 Google Compute Engine 的混合体 或类似的东西,它们都是(部分)Google Cloud Platform。
标签: google-app-engine google-cloud-sql google-flexible