How to setup Spring/Heroku/postgres SSL datasource

前端 未结 4 1790
孤独总比滥情好
孤独总比滥情好 2020-12-25 08:16

I\'m trying to create a datasource from my Heroku/Spring application to postgres.heroku.com postgres database. Here is my applicationContext.xml snippet.

<
相关标签:
4条回答
  • 2020-12-25 08:24

    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

    0 讨论(0)
  • 2020-12-25 08:31

    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

    0 讨论(0)
  • 2020-12-25 08:36

    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
    
    0 讨论(0)
  • 2020-12-25 08:46

    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

    0 讨论(0)
提交回复
热议问题