title: Spring Boot JDBC Connection to Google Cloud SQL not working
body: <p>I want to start by saying that when I run this locally, it works perfectly. When I deploy (./mvnw -DskipTests=true appengine:deploy) I deploys just fine with no errors and even appears to run on google cloud just fine. But when I try to use the registration form, i get the following error on submission. </p>
  
  <pre><code>Whitelabel Error Page
  This application has no explicit mapping for /error, so you are seeing this as a fallback.
  
  Wed Mar 07 22:48:57 UTC 2018
  There was an unexpected error (type=Internal Server Error, status=500).
  Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
  </code></pre>
  
  <p>MY POM FILE</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
  &lt;groupId&gt;com.myApp&lt;/groupId&gt;
  &lt;artifactId&gt;myApp-server&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;jar&lt;/packaging&gt;
  
  &lt;name&gt;trading-server&lt;/name&gt;
  &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
  &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;2.0.0.RELEASE&lt;/version&gt;
      &lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
  &lt;/parent&gt;
  
  
  &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
      &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
  
      &lt;mysql-connector.version&gt;6.0.5&lt;/mysql-connector.version&gt;
      &lt;mysql-socket-factory.version&gt;1.0.5&lt;/mysql-socket-factory.version&gt;
  
  &lt;/properties&gt;
  
  &lt;dependencies&gt;
  
      &lt;!-- Spring Boot Dependencies --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-cache&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Thymeleaf --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
          &lt;artifactId&gt;thymeleaf-extras-springsecurity4&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.thymeleaf.extras&lt;/groupId&gt;
          &lt;artifactId&gt;thymeleaf-extras-java8time&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Spring Security --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
      &lt;/dependency&gt;
  
  
      &lt;!-- Database Dependencies --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;mysql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
          &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
  
          &lt;!-- MySQL Socket Factory for Cloud SQL --&gt;
          &lt;groupId&gt;com.google.cloud.sql&lt;/groupId&gt;
          &lt;artifactId&gt;mysql-socket-factory&lt;/artifactId&gt;
          &lt;version&gt;1.0.3&lt;/version&gt;
      &lt;/dependency&gt;
  
  
      &lt;!-- Test Dependencies --&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
          &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Caching Dependencies --&gt;
      &lt;!-- &lt;dependency&gt; &lt;groupId&gt;javax.cache&lt;/groupId&gt; &lt;artifactId&gt;cache-api&lt;/artifactId&gt; 
          &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.ehcache&lt;/groupId&gt; &lt;artifactId&gt;ehcache&lt;/artifactId&gt; 
          &lt;/dependency&gt; --&gt;
  
      &lt;!-- Webjars Dependencies --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.webjars&lt;/groupId&gt;
          &lt;artifactId&gt;webjars-locator&lt;/artifactId&gt;
          &lt;version&gt;0.32&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.webjars&lt;/groupId&gt;
          &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
          &lt;version&gt;3.3.7-1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.webjars&lt;/groupId&gt;
          &lt;artifactId&gt;jquery&lt;/artifactId&gt;
          &lt;version&gt;3.3.1-1&lt;/version&gt;
      &lt;/dependency&gt;
  
  
  &lt;/dependencies&gt;
  
  &lt;build&gt;
      &lt;!-- START plugin --&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;com.google.cloud.tools&lt;/groupId&gt;
              &lt;artifactId&gt;appengine-maven-plugin&lt;/artifactId&gt;
              &lt;version&gt;${appengine.maven.plugin}&lt;/version&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
      &lt;!-- END plugin --&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>
  
  <p>APPLICATION PROPERTIES</p>
  
  <pre><code>    ## DATABASE
      database=mysql
      #spring.datasource.schema=classpath*:db/${database}/schema.sql
      spring.datasource.data=classpath*:db/${database}/data.sql
  
      # Web
      spring.thymeleaf.mode=HTML
  
      # Hibernate
      hibernate.dialect.storage_engine = innodb
  
      # JPA
      spring.jpa.hibernate.ddl-auto=none
      spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
  
      # Spring Actuator Settings
      management.endpoints.web.exposure.include=health,info,beans,env,metrics,mapping,trace,sessions
      management.endpoints.web.base-path=/actuator
  
  
      # Active Spring profiles
      spring.profiles.active=mysql
  </code></pre>
  
  <p>APPLICATION-MYSQL.PROPERTIES</p>
  
  <pre><code>database=mysql
  spring.datasource.driverClassName=com.mysql.jdbc.Driver
  spring.datasource.url=jdbc:mysql://google/database?cloudSqlInstance=spring-test:us-central1:spring-main=com.google.cloud.sql.mysql.SocketFactory
  #spring.datasource.url=jdbc:mysql://###.#.#.#/database?cloudSqlInstance=spring-test:us-central1:spring-main=com.google.cloud.sql.mysql.SocketFactory
  spring.datasource.username=root
  spring.datasource.password=secret
  
  spring.datasource.initialize=true
  </code></pre>
  
  <p>So again this works perfectly when I comment when i switch datasource.url above and run it locally. But I get the following error when I try to register an account on google cloud sql:</p>
  
  <pre><code>Whitelabel Error Page
  This application has no explicit mapping for /error, so you are seeing this as a fallback.
  
  Wed Mar 07 22:48:57 UTC 2018
  There was an unexpected error (type=Internal Server Error, status=500).
  Unable to acquire JDBC Connection; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
  </code></pre>