Pergunta

I have spring app deployed to heroku. I have database.properties file to kept database information. Now, I want to connect my heroku database from this properties file.

database.properties file:

database.driverClassName=org.postgresql.Driver
database.url=jdbc\:postgresql\://host\:5432/dbname
database.username=username
database.password=pass
ssl=true
sslfactory=org.postgresql.ssl.NonValidatingFactory

I am getting this error:

no pg_hba.conf entry for host "somehost", user "someuser", database "somedb", SSL off
Foi útil?

Solução 2

I was just playing with some settings to find how to inject this parameters:

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

Basically, we need to add this in databaseUrl, but in my spring roo app, it doesnt allow me to do it..

But there is another property named connectionProperties inside org.apache.commons.dbcp.BasicDataSource bean in appcontext.xml .

applicationContext.xml:

 <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
        <property name="driverClassName" value="${database.driverClassName}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
        <property name="connectionProperties" value="ssl=true;sslfactory=org.postgresql.ssl.NonValidatingFactory"></property>

Its working but there is one problem, When i run my app, It takes minimum 5 minutes to startup! So i needed to increase my tomcat's timeout setting. Hope this helps someone! Cheers:)

Outras dicas

By default PostgreSQL denies remote connections, you must enable the remote connections. Take a look at http://www.turnkeylinux.org/docs/database-remote-access

database.properties is only used to fill applicationContext.xml values (by context:property-placeholder tag definition). So, if you don't modify the dataSource bean definition, your new properties will do nothing.

To solve your problem follow this steps:

  1. Modify "database.properties" to include datatabase. as prefix of ssl and sslfactory property names.

  2. Modify applicationContext.xml like this:

    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
      <property name="driverClassName" value="${database.driverClassName}"/>
      <property name="url" value="${database.url}"/>
      <property name="username" value="${database.username}"/>
      <property name="password" value="${database.password}"/>
      <property name="ssl" value="${database.ssl}"/> <!-- NEW -->
      <property name="sslFactory" value="${database.sslfactory}"/> <!-- NEW -->
      <property name="testOnBorrow" value="true"/>
      ....
      ....
    </bean>
    
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top