How to integrate HikariCP in Dropwizard 1.3.8 application?

318 views
Skip to first unread message

Nikola Stevanović

unread,
Sep 7, 2020, 6:59:17 AM9/7/20
to dropwizard-user

Hi everyone,

I have issue with implementing HikariCP in my Dropwizard 1.3.8 app. Project uses Maven as build tool so I've added following dependency from this https://github.com/mtakaki/dropwizard-hikaricp/tree/1.3.x link:

  
<dependency>
 
<groupId>com.github.mtakaki</groupId>
 
<artifactId>dropwizard-hikaricp</artifactId>
 
<version>1.3.8</version>
</dependency>


...under my dependencies tag. As mentioned in link I'm supposed to get:

INFO [2016-03-14 06:32:06,681] org.eclipse.jetty.util.log: Logging initialized @1894ms
INFO [2016-03-14 06:32:08,675] com.zaxxer.hikari.HikariDataSource: hibernate - Starting...

message in my logs but unfortunatelly I don't.

Do I need to create some kind of Bundle and if yes how (simple example would be nice), if not then what else?


Any kind of help/advice is greatly appreciated.

Jochen Schalanda

unread,
Sep 7, 2020, 3:24:37 PM9/7/20
to dropwizard-user
Hi Nikola,

the bundle looks a bit weird. Make sure to add the DataSourceFactory from the Hikari Bundle to your application configuration and make sure that dropwizard-db is not part of your application.

Take a look at the unit test for an example:



Cheers,
Jochen

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/dropwizard-user/3cbdc158-f5cd-4d2a-b575-6673c2352bd3o%40googlegroups.com.

Message has been deleted

Nikola Stevanović

unread,
Sep 7, 2020, 6:22:04 PM9/7/20
to dropwizard-user
Hi Jochen,
thank you for suggestion and examples. Since I'm newbie with Dropwizard and don't have expreince with setting up Bundles (NEVER done it) can you please give me some link with simple tutorial/explanation how to configure it?

I'm struggling to set it up cause I don't use Hibernate in my application for creating queries, but jDBI3 so Hibernate does not work for me + I'm NOT using Dependency Injection in my project so since it's small project it instantiates objects manually in run() method.
I've found code example on this https://github.com/DeloitteDigitalUK/dropwizard-hikaricp/tree/master/src/main/java/uk/co/deloittedigital/dropwizard/hikari repo, edited my project and got this message in Console when I run my app (it compiles successfully with mvn clean package command):
 
java.lang.ClassCastException: com.nikolas.master_thesis.DropwizardMasterThesisConfiguration cannot be cast to com.nikolas.master_thesis.config.HikariConfigurationProvider

...and here are classes which this message is reffering to:
Thank you in advance.

Peter Stackle

unread,
Sep 7, 2020, 8:02:51 PM9/7/20
to dropwizard-user
Hi Nikola,

It looks to me like the following are two different projects to integrate HikariCP into a Dropwizard app. I think you need to pick just one to use (if you require HikariCP instead of the Tomcat JDBC connection pool library). 

It's worth pointing out that neither of these libraries are part of the official Dropwizard project, which comes with out of the box integration with the Tomcat JDBC Connection Pool library. 

If you need HikariCP and assuming you are using the first library, it looks like it provides replacement classes for a couple of the classes in the dropwizard-db library (the ones that provide integration with the Tomcat connection pool), but seems that it relies on the ordering of which library shows up on your application's classpath first. You should make sure that the com.github.mtakaki:dropwizard-hikaricp dependency shows up above the io.dropwizard:dropwizard-db dependency in your application's pom.xml file.

Since you are using JDBI3 for your application, my suggestion would be to start by following the instructions at this link: https://www.dropwizard.io/en/latest/manual/jdbi3.html
and get things working before starting to integrate HikariCP. Once you have things working correctly, then introduce the com.github.mtakaki:dropwizard-hikaricp dependency _above_ your io.dropwizard:dropwizard-db dependency in your application's pom.xml file. You can use Maven's `mvn dependency:build-classpath` command to display the classpath that Maven determined and you can double check that the dropwizard-hikaricp classes are loaded earlier than the dropwizard-db classes. 
You could also set breakpoints in the classes to see that the correct ManagedPooledDataSource class is used. 


On an unrelated note, in looking at your application class, I noticed that you are setting up a MetricRegistry and integrating that in with a JmxReporter. The Dropwizard framework has out of the box integration with the Metrics library and automatically sets up a MetricRegistry and wires it up with a JmxReporter. You can see that happen in the Bootstrap class: https://github.com/dropwizard/dropwizard/blob/master/dropwizard-core/src/main/java/io/dropwizard/setup/Bootstrap.java#L79-L97
This integration is what allows you to put a @Timed annotation on your resource methods and get metrics automatically recorded: https://www.dropwizard.io/en/latest/manual/core.html#metrics  

I hope that helps,
Peter

Nikola Stevanović

unread,
Sep 9, 2020, 10:37:14 AM9/9/20
to dropwizard-user
Hi Petere,
thank you for suggestions, I will definetly try to do what you've mentioned. For now I've decided to go with default Tomcat Connection Pool as I have other things going on which are priority.
I'll give feedback ASAP. :)

Regards,
Nikola
Reply all
Reply to author
Forward
0 new messages