title: Spring boot and GCP - Connecting Cloud SQL instance with spring-cloud-gcp-starter-sql-postgresql tries SSL and it delays to start
body: <p>I have a Spring boot project that should connect with an instance of Cloud SQL with <code>spring-cloud-gcp-starter-sql-postgresql</code> in order to avoid the explicit use of an IP in the project.</p>
  
  <p>So far, It connects well but it delayed a lot (around 30 seconds to start) because it tries to connect via SSL socket and after a lot of tries, it connects.</p>
  
  <p>In the logs there is a line that says:</p>
  
  <pre><code>2020-02-19 00:10:09.809  INFO 6779 --- [           main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Default POSTGRESQL JdbcUrl provider. Connecting to jdbc:postgresql://google/test?socketFactory=com.google.cloud.sql.postgres.SocketFactory&amp;cloudSqlInstance=XXXXXX:us-central1:test&amp;useSSL=false with driver org.postgresql.Driver
  </code></pre>
  
  <p>As long as I know, the parameter <code>useSSL=false</code> won't work for postgresql. The correct one is <code>ssl=false</code> but when I try to overwrite the JDBC Url with the application.yml, It prints the following log:</p>
  
  <pre><code>2020-02-19 00:10:09.816  WARN 6779 --- [           main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Ignoring provided spring.datasource.url. Overwriting it based on the spring.cloud.gcp.sql.instance-connection-name.
  </code></pre>
  
  <p>I suspect that the delay is because of the SSL connection. So I have two questions:</p>
  
  <ol>
  <li>How can I avoid the use of SSL connection? Since I am not setting a JDBC URL explicitly, I cannot use the <code>ssl=false</code> in the parameter.</li>
  <li>I suspect that is delaying because the SSL Client certificate is not set. If this is the case, how can I set it? I already have the .pem but I don't know how to implement it</li>
  </ol>
  
  <p>I add my <code>application.yml</code> with configurations and the mentioned log:</p>
  
  <ul>
  <li>application.yml</li>
  </ul>
  
  <pre><code>spring:
    cloud:
      gcp:
        project-id: xxxxxxx
        config
        sql:
          instance-connection-name: xxxxxxx:us-central1:test
          database-name: test
          enabled: true
    datasource:
      username: test
      password: 123456
      initialization-mode: always
  
  
    jpa:
      hibernate:
        ddl-auto: update
  </code></pre>
  
  <p>The credentials are set in a environment variable "GOOGLE_APPLICATION_CREDENTIALS" calling the service account json</p>
  
  <ul>
  <li>Log:</li>
  </ul>
  
  <pre><code>2020-02-19 00:10:09.692  INFO 6779 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
  2020-02-19 00:10:09.699  INFO 6779 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
  2020-02-19 00:10:09.699  INFO 6779 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.30]
  2020-02-19 00:10:09.767  INFO 6779 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
  2020-02-19 00:10:09.767  INFO 6779 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 790 ms
  2020-02-19 00:10:09.809  INFO 6779 --- [           main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Default POSTGRESQL JdbcUrl provider. Connecting to jdbc:postgresql://google/test?socketFactory=com.google.cloud.sql.postgres.SocketFactory&amp;cloudSqlInstance=XXXXXXX:us-central1:test&amp;useSSL=false with driver org.postgresql.Driver
  2020-02-19 00:10:09.816  WARN 6779 --- [           main] o.s.c.g.a.s.GcpCloudSqlAutoConfiguration : Ignoring provided spring.datasource.url. Overwriting it based on the spring.cloud.gcp.sql.instance-connection-name.
  2020-02-19 00:10:09.885  INFO 6779 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
  2020-02-19 00:10:09.940  INFO 6779 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.4.10.Final}
  2020-02-19 00:10:10.039  INFO 6779 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
  2020-02-19 00:10:10.109  INFO 6779 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
  2020-02-19 00:10:10.193  INFO 6779 --- [           main] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:10.193  INFO 6779 --- [           main] c.g.cloud.sql.core.CoreSocketFactory     : First Cloud SQL connection, generating RSA key pair.
  2020-02-19 00:10:13.690  INFO 6779 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
  2020-02-19 00:10:13.711  INFO 6779 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
  2020-02-19 00:10:13.791  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:15.042  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:16.333  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:17.653  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:19.314  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:20.643  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:21.938  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:23.227  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:24.561  INFO 6779 --- [onnection adder] c.g.cloud.sql.core.CoreSocketFactory     : Connecting to Cloud SQL instance [XXXXXXX:us-central1:test] via SSL socket.
  2020-02-19 00:10:35.164  INFO 6779 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
  2020-02-19 00:10:35.173  INFO 6779 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
  2020-02-19 00:10:35.294  WARN 6779 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
  2020-02-19 00:10:35.507  INFO 6779 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
  2020-02-19 00:10:35.611  INFO 6779 --- [           main] o.s.c.g.core.DefaultCredentialsProvider  : Default credentials provider for service account cloud-code@XXXXXXX.iam.gserviceaccount.com
  2020-02-19 00:10:35.612  INFO 6779 --- [           main] o.s.c.g.core.DefaultCredentialsProvider  : Scopes in use by default credentials: [https://www.googleapis.com/auth/pubsub, https://www.googleapis.com/auth/spanner.admin, https://www.googleapis.com/auth/spanner.data, https://www.googleapis.com/auth/datastore, https://www.googleapis.com/auth/sqlservice.admin, https://www.googleapis.com/auth/devstorage.read_only, https://www.googleapis.com/auth/devstorage.read_write, https://www.googleapis.com/auth/cloudruntimeconfig, https://www.googleapis.com/auth/trace.append, https://www.googleapis.com/auth/cloud-platform, https://www.googleapis.com/auth/cloud-vision, https://www.googleapis.com/auth/bigquery]
  2020-02-19 00:10:35.612  INFO 6779 --- [           main] o.s.c.g.a.c.GcpContextAutoConfiguration  : The default project ID is XXXXXXX
  2020-02-19 00:10:35.730  INFO 6779 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
  2020-02-19 00:10:35.733  INFO 6779 --- [           main] c.r.c.CloudSqlTestApplication            : Started CloudSqlTestApplication in 27.027 seconds (JVM running for 27.464)
  </code></pre>
  
  <p>Also, just in case it helps, i am adding my <code>pom.xml</code>:</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 https://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&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.2.4.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.ramonparis&lt;/groupId&gt;
      &lt;artifactId&gt;cloud-sql-test&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;cloud-sql-test&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;spring-cloud.version&gt;Hoxton.SR1&lt;/spring-cloud.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&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;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-gcp-starter&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;version&gt;2.2.4.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-gcp-starter-sql-postgresql&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
             ........
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;
                  &lt;version&gt;${spring-cloud.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;build&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;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  
  </code></pre>