Is it possible to configure multiple database connections in Dropwizard?

1,732 views
Skip to first unread message

jon....@gmail.com

unread,
Jan 18, 2014, 8:41:57 PM1/18/14
to dropwiz...@googlegroups.com
I am working on some code that leverages Dropwizard that will require that I need to connect to at least two different databases (I plan to use Hibernate as well). I was unable to find any examples/documentation that will allow me to configure two different database connections in the Database block of the .yml configuration file. Is this possible in Dropwizard? If not, what are the workarounds that people have used in the past. Thank you in advanced for your help!

Carlo Barbara

unread,
Jan 18, 2014, 11:46:39 PM1/18/14
to dropwiz...@googlegroups.com

Totally possible. See this

https://groups.google.com/forum/m/#!topic/dropwizard-user/mUTIfz0E8P4

On Jan 18, 2014 8:41 PM, <jon....@gmail.com> wrote:
I am working on some code that leverages Dropwizard that will require that I need to connect to at least two different databases (I plan to use Hibernate as well). I was unable to find any examples/documentation that will allow me to configure two different database connections in the Database block of the .yml configuration file. Is this possible in Dropwizard? If not, what are the workarounds that people have used in the past. Thank you in advanced for your help!

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

jon....@gmail.com

unread,
Jan 19, 2014, 11:39:43 AM1/19/14
to dropwiz...@googlegroups.com
Thank you Carlo for the reply. How would I go about setting up the .yml file to provide the two database connection configurations? Would I just add two database blocks in the configuration file? Thanks again for your help.

jon....@gmail.com

unread,
Jan 19, 2014, 12:10:47 PM1/19/14
to dropwiz...@googlegroups.com
I think I found the answer to my question. Thank you again for your help!

Carlo Barbara

unread,
Jan 19, 2014, 12:11:14 PM1/19/14
to dropwiz...@googlegroups.com
database1:
  driverClass: org.h2.Driver
  user: sa
  password: sa
  url: jdbc:h2:target/example
database2:
  driverClass: org.h2.Driver
  user: sa
  password: sa
  url: jdbc:h2:target/example

Then in your config class, like the one below, you would have 2 DataSourceFactory. Each with json properties named database1 and database2



On Sun, Jan 19, 2014 at 11:39 AM, <jon....@gmail.com> wrote:
Thank you Carlo for the reply. How would I go about setting up the .yml file to provide the two database connection configurations? Would I just add two database blocks in the configuration file? Thanks again for your help.

jon....@gmail.com

unread,
Jan 19, 2014, 1:48:05 PM1/19/14
to dropwiz...@googlegroups.com
Thanks for following up Carlo! That was exactly what it was looking for. Thanks!
Reply all
Reply to author
Forward
0 new messages