我似乎无法让这个工作..
我正在使用 Google Flexible Environment ,并希望连接到我的第二代Cloud SQL 数据库。我目前正在获得此例外:
[main] ERROR com.mahlzeit.server.BootstrappingServerConfig - Error trying to migrate SQL scripts ..
org.flywaydb.core.api.FlywayException: Unable to obtain Jdbc connection from DataSource
at org.flywaydb.core.internal.util.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56)
at org.flywaydb.core.Flyway.execute(Flyway.java:1385)
at org.flywaydb.core.Flyway.migrate(Flyway.java:1006)
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory;' due to underlying exception:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
...
Caused by: java.lang.ClassNotFoundException: com/google/cloud/sql/mysql/SocketFactory;
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.mysql.jdbc.MysqlIO.createSocketFactory(MysqlIO.java:3321)
...
这就是我配置DataSource
的方式:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://google/mz_db?cloudSqlInstance=mz-test:us-central1:mz-life-cloudsql-prod&socketFactory=com.google.cloud.sql.mysql.SocketFactory;" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
我已将mysql-socket-factory
添加为依赖项:
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.0</version>
</dependency>
那为什么我得到这个例外?
答案 0 :(得分:4)
你最后有一个分号,所以它试图加载一个名为com.google.cloud.sql.mysql.SocketFactory;
的类。尝试删除末尾的分号。