brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.83k stars 2.92k forks source link

Google Cloud SQL cloudSqlInstance property not set #1425

Open AniketBhadane opened 5 years ago

AniketBhadane commented 5 years ago

I wish to connect to Google Cloud SQL using JDBC SocketFactory with HikariCP in a Spring 4 application.

The dependencies in pom.xml are:

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.1.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>postgres-socket-factory</artifactId>
            <version>1.0.14</version>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>3.3.1</version>
        </dependency>

The applicationContext.xml contains:

    <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
        <property name="poolName" value="springHikariCP" />
        <property name="connectionTestQuery" value="SELECT 1" />
        <property name="dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource" />
        <property name="maximumPoolSize" value="10" />
        <property name="idleTimeout" value="30000" />

        <property name="dataSourceProperties">
            <props>
                <prop key="url">jdbc:postgresql://google/mydb?cloudSqlInstance=projectId:region:instance&amp;socketFactory=com.google.cloud.sql.postgres.SocketFactory</prop>
                <prop key="user">postgres</prop>
                <prop key="password">password</prop>
            </props>
        </property>
    </bean>

But when I run the application, I get the following exception:

Caused by: java.lang.IllegalArgumentException: cloudSqlInstance property not set. Please specify this property in the JDBC URL or the connection Properties with value in form "project:region:instance" at com.google.common.base.Preconditions.checkArgument(Preconditions.java:135) at com.google.cloud.sql.core.CoreSocketFactory.connect(CoreSocketFactory.java:170) at com.google.cloud.sql.postgres.SocketFactory.createSocket(SocketFactory.java:72) at org.postgresql.core.PGStream.(PGStream.java:60) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) at org.postgresql.jdbc.PgConnection.(PgConnection.java:194) at org.postgresql.Driver.makeConnection(Driver.java:450) at org.postgresql.Driver.access$100(Driver.java:60) at org.postgresql.Driver$ConnectThread.run(Driver.java:360) ... 1 common frames omitted

What could be going wrong here?

Environment

HikariCP version: 3.3.1
JDK version     : 1.8
Database        : Google Cloud SQL Postgres
veslav3 commented 4 years ago

Shouldn't it be with three slashes?: jdbc:postgresql:///google