2

im trying to deploy my spring boot app to Google App Engine Flex Environment and G Cloud MySQL DB.

I'm having issues connecting to the db.

Tried already some variants, but all unsuccessful. spring-boot-with-google-cloud-datastore-api-fails-to-run

My properties:

spring:
profiles: googlecloud
  jpa:
    database: MYSQL
    show-sql: false
    hibernate:
      ddl-auto: update
  datasource:
    url: jdbc:mysql://google/myproject?cloudSqlInstance=XXXX&user=xxx&password=xxx

My pom.xml (the db dependencies only):

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>
    <dependency>
        <groupId>com.google.cloud.sql</groupId>
        <artifactId>mysql-socket-factory</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
        <version>1.0.2</version>
    </dependency>

With this configuration, im getting:

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.SocketFactory

...Error creating repository beans...

java.lang.NoClassDefFoundError: com/mysql/jdbc/SocketFactory

Community
  • 1
  • 1
Nacho
  • 2,057
  • 2
  • 23
  • 32

1 Answers1

2

You can read more details about the change from 5x to 6x connector : https://dev.mysql.com/doc/connector-j/6.0/en/connector-j-api-changes.html

For the NCDF exception, according to this issue : https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory/issues/18

I think you have to change your dependencies :

<dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.6</version>
    </dependency>

    <dependency>
        <groupId>com.google.cloud.sql</groupId>
        <artifactId>mysql-socket-factory-connector-j-6</artifactId>
        <version>1.0.2</version>
    </dependency>
OlivierTurpin
  • 308
  • 1
  • 4