Starting Dropwizard Microservices

DZone 's Guide to

Starting Dropwizard Microservices

I read about Dropwizard when I started using Spring Boot, but decided to stick with Spring as I am more familiar with it. When I read Building Microservices by Sam Newman, I thought I should look at Dropwizard again and learn more about it.

· Integration Zone ·
Free Resource

I read about Dropwizard when I started using Spring Boot, but decided to stick with Spring as I am more familiar with Spring. Then I read the book Building Microservices by Sam Newman, and he recommended Dropwizard for microservices development. So I thought I should look at Dropwizard again, and learn more about it.

What Is Dropwizard?

Dropwizard provided the inspiration for spring boot. It is not a framework, but a collection of best-of-breed libraries and provides:

...out-of-the-box support for sophisticated configuration, application metrics, logging, operational tools, and much more...

At its core are:

It also includes metrics, Logback, and slf4jLiquidbaseFreemarker and Mustache; and Joda Time.

The final product is a single big JAR that can be run standalone.

Sample Project

The build system for Dropwizard is Maven. I don't have strong feelings on this, and maven is fine for me.

The basic .pom has just a Dropwizard dependency:


It also uses the shade plugin to generate the big JAR:

         <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
         <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

The core of the application is the "Application" class:

public class TodaysDateApplication extends Application<TodaysDateConfiguration> {

   public static void main(String[] args) throws Exception {
      new TodaysDateApplication().run(args);

   public String getName() {
      return "TodaysDate-microservice";

   public void initialize(Bootstrap<TodaysDateConfiguration> bootstrap) {

   public void run(TodaysDateConfiguration configuration, Environment environment) throws Exception {
      environment.jersey().register(new TodaysDateResource());
      environment.HealthCheck().register("TodaysDateHC", new TodaysDateHealthCheck());


The key points are:

  • The main method starts an instance of the Jersey server
  • The run method then sets up two parameters
  • REST server: TodaysDateResource
  • HealthCheck class, TodaysDateHealthCheck (this isn't necessary but you do get a warning on startup if you don't set one)

The configuration class itself is just a placeholder:

public class TodaysDateConfiguration extends Configuration {

We can add our own configuration here to accept parameters from the .yml config file.

The HealthCheck class is also quite basic, and just increments a count on the number of times the service is called:

public class TodaysDateHealthCheck extends HealthCheck {

   protected Result check() throws Exception {
      return Result.healthy();


In a real example, we could use this to monitor key resources and feed it back based on whether external connections or services are active.

Finally, we get to the core of the application:

public class TodaysDateResource {

   public String todaysDate() {
      return "{\"todaysdate\": " + new DateTime().toString("dd/MM/yyyy") + "}";


This is simply a Jersey REST application:

  • Serves on path /todaysdate, and returns a JSON message like - { "todaysdate" : "12/04/2016" }  

There is one additional configuration file—config.yml:

  level: INFO

  - type: http 
    port: 8080
  - type: http
    port: 8001

YML is an extension of JSON, and is designed to be human readable. I hadn't used it before, but it's just another configuration format and easy to understand. I added some additional information to let you change server ports.

Putting it all together

mvn clean package
java -jar target/dropwizard-dates-microservice-0.0.1-SNAPSHOT.jar server src/main/resources/server-config.yml

You can then access the service through your browser at:


The output is the date in UK format:

{"todaysdate": 12/04/2016 }

The next feature is HealthCheck:


   "TodaysDateHC" : 
      "healthy" : true
   "deadlocks" : 
      "healthy" : true


It's too soon to draw meaningful conclusions about Dropwizard, beyond concluding that a basic HelloWorld style microservice is fairly easy to implement. That said it, has a number of features I like: single JAR, standalone server, and the HealthCheck functionality. The next step will be to implement a more complete microservice example, and comparison against Spring Boot.

Source Code


dropwizard, java, microservices, spring boot

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}