Failed to create factory socket 'com.google.cloud.sql.mysql.SocketFactory;'

I can't get this to work.

I am using Google Flexible and want to connect to my second generation Cloud SQL database . I am currently getting this exception:

[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)
    ...

This is how I set up my own 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&amp;socketFactory=com.google.cloud.sql.mysql.SocketFactory;" />
    <property name="username" value="root" />
    <property name="password" value="" />
</bean>

I added mysql-socket-factoryas a dependency:

<dependency>
    <groupId>com.google.cloud.sql</groupId>
    <artifactId>mysql-socket-factory</artifactId>
    <version>1.0.0</version>
</dependency>

so why am i getting this exception?

+2
source share
1 answer

You have a semicolon at the end, so it is trying to load a class called com.google.cloud.sql.mysql.SocketFactory;Try removing the semicolon at the end.

+2
source

Source: https://habr.com/ru/post/1568395/


All Articles