Search code examples
herokudropwizard

Dropwizard crashing on Heroku


I am trying to deploy my Dropwizard project to Heroku.

I have added a Procfile and a Postgres DB to the Heroku app. My Procfile reads:

web: java $JAVA_OPTS -Ddw.server.connector.port=$PORT -Ddw.database.url=$DATABASE_URL -jar target/api-1.0-SNAPSHOT.jar server config.yml

When I try to deploy I receive the following error/crash message in the logs.

org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator: HHH000342: Could not obtain connection to query metadata : Driver:org.postgresql.Driver@53d13cd4 returned null for URL:postgres://fdeqzbddzbefaz:138912590e989b1b8fab5d169a1aea291f04b2d3bc040b1bbf6642a9207a5355@ec2-54-235-101-91.compute-1.amazonaws.com:5432/d67crr4pvqrfee
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
State changed from starting to crashed
Process exited with status 1

My config.yml reads

database:
 # the name of your JDBC driver
 driverClass: org.postgresql.Driver

 # the username
 user: localusername

 # the JDBC URL
 url: jdbc:postgresql://localhost/dbname

# use the simple server factory if you only want to run on a single port
# HEROKU NOTE - the port gets be overridden with the Heroku $PORT in the Procfile
server:
  type: simple
  applicationContextPath: /
  #adminContextPath: /admin # If you plan to use an admin path, you'll need to also use non-root app path
  connector:
    type: http
    port: 8080

Does anyone have any trouble shooting ideas?


Solution

  • The DATABASE_URL env var is not directly compatible with the JDBC URL format. See docs. Specifically,

    The DATABASE_URL for the Heroku Postgres add-on follows the below convention

    postgres://username:password@host:port/dbname

    However the Postgres JDBC driver uses the following convention:

    jdbc:postgresql://host:port/dbname?user=username&password=password

    Instead, try using JDBC_DATABASE_URL as documented here