简体   繁体   中英

How to connect a spring boot application hosted on Google cloud engine to a mysql db?

I want to deploy my java spring boot application on Google cloud engine. It works well when I do not configure a db. But then when I use jpa, it just cannot find the connection. I tried multiple approached but non worked so far.

spring:
    jpa:
        database: MYSQL
        show-sql: false
        hibernate:
          ddl-auto: update
    datasource:
        driver-class-name: com.mysql.jdbc.GoogleDrive
        username: root
        password: ********
        url: jdbc:google:mysql://something-app:us-central1:something/something?user=root

This is the last config that I tried but it cannot find the driver. I have this in my pom.cml

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

Any idea of what I am doing wrong. Or example (github or other) that has it working?

stack trace:

2016-10-08 14:13:13 default[20161008t161026]  java.sql.SQLException: Driver:com.google.appengine.api.rdbms.AppEngineDriver@746b25b1 returned null for URL:jdbc:google:mysql://something-app:us-central1:something/something?user=root

I finally got it working with the following configuration.

spring:
    jpa:
        database: MYSQL
        show-sql: false
        hibernate:
          ddl-auto: update
    datasource:
        url: jdbc:mysql://google/myproject?cloudSqlInstance=myproject-app:us-central1:myproject&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=******&password=**********

I used this in the pom.xml

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM