如何设置Spring / Heroku / postgres SSL数据源 [英] How to setup Spring/Heroku/postgres SSL datasource

查看:273
本文介绍了如何设置Spring / Heroku / postgres SSL数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的Heroku / Spring应用程序创建一个数据源到postgres.heroku.com postgres数据库。这是我的 applicationContext.xml 代码片段。

 < bean id =securityDataSourceclass =org.apache.commons.dbcp.BasicDataSource> 
< property name =driverClassNamevalue =org.postgresql.Driver/>
< property name =urlvalue =jdbc:postgresql:// url / dstabase/>
< property name =usernamevalue =user/>
< property name =passwordvalue =password/>
< / bean>

但是当我运行这个应用时,tomcat会给出这个错误:

无法创建PoolableConnectionFactory(FATAL:没有pg_hba.conf条目,主机10.11.12.13,用户用户名,数据库数据库 ,SSL关闭)

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

解决方案

您需要扩展JDBC连接URL相关的ssl信息。

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

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

该URL将是:

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

此资讯来源:
https://devcenter.heroku.com / articles / connected-to-relational-databases-on-heroku-with-java#连接数据库远程


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

解决方案

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

这篇关于如何设置Spring / Heroku / postgres SSL数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆