如何设置Spring/Heroku/postgres SSL数据源

Joa*_*rey 16 postgresql ssl spring heroku

我正在尝试从我的Heroku/Spring应用程序创建一个数据源到postgres.heroku.com postgres数据库.这是我的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>
Run Code Online (Sandbox Code Playgroud)

但是当我运行应用程序时,tomcat会出现此错误:

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

如何配置它以使用SSL?我需要它来建立与postgres.heroku.com的连接

DB5*_*DB5 24

您需要使用相关的ssl信息扩展JDBC连接URL.

您的JDBC连接URL需要包含以下内容:

ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
Run Code Online (Sandbox Code Playgroud)

所以在你的情况下,URL将是:

jdbc:postgresql://url/dstabase?ssl=true&amp;sslfactory=org.postgresql.ssl.NonValidatingFactory
Run Code Online (Sandbox Code Playgroud)

此信息的来源:https: //devcenter.heroku.com/articles/connecting-to-relational-databases-on-heroku-with-java#connecting-to-a-database-remotely


iaL*_*iaL 5

以下为我工作:

jdbc:postgresql://url/databaseName?sslmode=require&amp;sslfactory=org.postgresql.ssl.NonValidatingFactory
Run Code Online (Sandbox Code Playgroud)

我倒是要改变ssl=truesslmode=require