17

Heroku/Springアプリケーションからpostgres.heroku.compostgresデータベースにデータソースを作成しようとしています。これが私のapplicationContext.xmlスニペットです。

<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>

しかし、アプリを実行すると、tomcatは次のエラーを出します。

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

SSLを使用するように構成するにはどうすればよいですか?postgres.heroku.comとの接続を確立するために必要です

4

4 に答える 4

28

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

于 2012-08-07T09:21:04.923 に答える
5

Following worked for me:

jdbc:postgresql://url/databaseName?sslmode=require&amp;sslfactory=org.postgresql.ssl.NonValidatingFactory

I'd to change ssl=true to sslmode=require

于 2017-10-25T13:25:23.417 に答える
4

When connecting to Heroku Postgres with jdbc, you will also sometimes get an error unless you add the SSL parameters to the url:

ssl=true
sslfactory=org.postgresql.ssl.NonValidatingFactory
于 2013-09-01T02:49:38.133 に答える
3

It worked for me:

  <bean id="securityDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="org.postgresql.Driver"/>
        <property name="url" value="jdbc:postgresql://host:port/database?ssl=true&amp;sslfactory=org.postgresql.ssl.NonValidatingFactory"/>
        <property name="username" value="user"/>
        <property name="password" value="password"/>
    </bean>

The mistake I was doing was using an & instead of &amp; (silly I know)

 ?ssl=true&amp;sslfactory=org.postgresql.ssl.NonValidatingFactory

and yes the link definitely is helpful: https://devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#connecting-to-a-database-remotely

AND Keep in mind: in this link, jdbc:postgres://host.. is used, which might not be suitable for you (use postgresql instead) if No suitable Sql driver error occurs

于 2014-07-12T18:32:08.097 に答える