Social Media

Dropwizard Microservices

I had read about Dropwizard when I started using Spring Boot, but decided to stick with Spring as I was more familiar with Spring. Then I read Building Microservices book, by Sam Reilly, and he recommended it 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 a collection of what it considers 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 is –

It also includes metrics, Logback and slf4j, Liquidbase, Freemarker and Mustache and Joda Time

The final product is a single big jar

Sample Project

dropwizard recommends maven so I’ll stick with that. Not much to our basic pom – just a dropwizard dependency –

[sourcecode lang=”xml”] <dependency>

We then use the shade plugin to create our big jar –
[sourcecode lang=”xml”] <plugin>
<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 –
[sourcecode lang=”java”] 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.healthChecks().register("TodaysDateHC", new TodaysDateHealthCheck());

The key points are –

  • The main method starts an instance of the jetty 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 –

[sourcecode lang=”java”] 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 –

[sourcecode lang=”java”] public class TodaysDateHealthCheck extends HealthCheck {
protected Result check() throws Exception {
return Result.healthy();

Finally we get to the core of the application –

[sourcecode lang=”java”] @Path("/todaysdate")
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 –

[sourcecode] logging:
level: INFO

– type: http
port: 8080
– type: http
port: 8001

The obvious question is what is, and why YML. Im told its human-friendly configuration, and to be honest it doesnt bother me whether config is xml, properties or whatever the framework is using as long as I can get the information I need. In this example I’ve included some config to allow you to change 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 –


[sourcecode lang=”json”]{"todaysdate": 12/04/2016 }[/sourcecode]


[sourcecode lang=”json”] {
"TodaysDateHC" : {
"healthy" : true
"deadlocks" : {
"healthy" : true


This example barely scrapes the surface of dropwizard, but half the battle of coding is to get a HelloWorld application to compile. Its also too soon to provide a comparison between Spring Boot and dropwizard just yet.

Source Code


About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: