Thursday, August 8, 2019

[google-cloud-sql-discuss] Re: HikariCP cloudSqlInstance property not set

Hi Anket - I've responded to your github issue on the subject: https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/issues/154

On Thursday, August 8, 2019 at 2:12:52 AM UTC-7, Aniket Bhadane wrote:
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 "proj
ect: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.<init>(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.<init>(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?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/ec6cf2ad-2a23-434b-95ff-ee860b8ed4cb%40googlegroups.com.

No comments:

Post a Comment