如何设置Spring / Heroku / postgres SSL数据源 [英] How to setup Spring/Heroku/postgres SSL datasource
问题描述
我试图从我的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
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&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屋!