I'm using Micronaut and trying to implement Hikari for connection to a PostgresSQL database. I've got it working on a local connection using a yml configuration
datasources:
default:
jdbcUrl: "jdbc:postgresql://127.0.0.1:3306/playland"
username: "user"
password: "password"
and it works great. The problem is, when I deploy it to App Engine, I need to use the following. I would prefer (I think) to add it to the yml configuration if possible but I can't seem to figure it out.
// For Java users, the Cloud SQL JDBC Socket Factory can provide authenticated connections.
// See https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory for details.
config.addDataSourceProperty("socketFactory", "com.google.cloud.sql.postgres.SocketFactory");
config.addDataSourceProperty("cloudSqlInstance", CLOUD_SQL_CONNECTION_NAME);
I've made it work using a config as explained in the tutorial but I'm running into issues incorporating the datasourceproperties into the yml configuration. I tried this based on another SO answer:
datasources:
default:
jdbcUrl: "jdbc:postgresql:///playland"
username: "user"
password: "password"
hikari:
data-source-properties:
socketFactory: "com.google.cloud.sql.postgres.SocketFactory"
cloudSqlInstance: "project:region:instance"
But it didn't work. Is there a way to add it or no?
Try using the full JDBC URL instead:
jdbc:postgresql:///<DATABASE_NAME>?cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&socketFactory=com.google.cloud.sql.postgres.SocketFactory&user=<POSTGRESQL_USER_NAME>&password=<POSTGRESQL_USER_PASSWORD>
Let me know if it works for you.