Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Spring/Heroku/postgres SSL datasource

I'm trying to create a datasource from my Heroku/Spring application to postgres.heroku.com postgres database. Here is my applicationContext.xml snippet.

<bean id="securityDataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbc:postgresql://url/dstabase"/>
    <property name="username" value="user"/>
    <property name="password" value="password"/>
</bean>

But when I run the app, tomcat gives this error:

Cannot create PoolableConnectionFactory (FATAL: no pg_hba.conf entry for host "10.11.12.13", user "username", database "database", SSL off)

How can I configure it to use SSL? I need it in order to stablish a connection against postgres.heroku.com

like image 459
Joan Camps Morey Avatar asked Aug 06 '12 16:08

Joan Camps Morey


People also ask

How do I get Heroku Postgres credentials?

To create the credential through data.heroku.com, select the Credentials tab and click the Create Credential button. The name should reflect the purpose of the credential. In the above example, limited_user is used as the credential's username when connecting to the database.


1 Answers

You need to extend your JDBC connection URL with the relevant ssl information.

Your JDBC connection URL will need to include the following:

ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

So in your case the URL would be:

jdbc:postgresql://url/dstabase?ssl=true&amp;sslfactory=org.postgresql.ssl.NonValidatingFactory

Source for this info: https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#connecting-to-a-database-remotely

like image 73
DB5 Avatar answered Oct 08 '22 08:10

DB5