dropwizardMigrating to Dropwizard version 0.7.0 was anything but straightforward so I thought I would share some of the migration changes need for upgrading to the latest release of from version 0.6.x. The Release notes are a good place to start, but beyond that any hints or guides for upgrading are pretty sparse. This will not be a complete guide and will only cover the specific issues I had to deal with. A working example is availbale at our GitHub project called XDropWizard. XDropWizard is a jump-start web application integrating and demonstrating several useful open source projects such as Yank, Sundial (a Quartz fork), Flot, Bootstrap, AngularJS, HSQLDB, XChart, JUnit, etc., and demonstrates how to serve static content, dynamic content loaded into Freemarker templates, using AJAX and more. The README file has clear instructions on how to build and deploy the app using Maven as well as explanations for how to integrate a plethora of capabilities into a Dropwizard-based web application and web service.

Dropwizard Namespace and Jars

Dropwizard’s namespace changed from com.yammer.dropwizard to io.dropwizard, so all your import statements and Maven pom dependencies need to be updated. Several Dropwizard modules were broken up into smaller modules, and it was required that extra dependencies were added to pom.xml. Following is an excerpt from the upgraded pom.

I originally only had the first two dependencies. One thing I struggled with for a while was an error relating to the FreeMarker views in the application. The error was:

Once I added the dropwizard-views-freemarker dependency, the error went away.

Dropwizard Configuration (YML) File

Converting the configuration file took the most amount of effort. Apparently the preferred way to access the admin features of Dropwizard is now via the same port as the application, but at a different root URL path. I also wasn’t sure if I should choose the simple server type of the default. I ended up using the simple option. Setting up logging was a pain as well as the official example Dropwizard app’s configuration file is very minimal. Getting my preferred console and file logging configured was a pain. I noticed that the yml file has to be perfectly formatted otherwise starting of the app will fail. Indenting and spacing must be perfect. Below are the before and after versions of the configurations file in XDropWizard.

Before (Version 0.6.x)

After (Version 0.7.0)

Service to Application

The Service class was renamed to Application, so you’ll need to change that right away. In the initialize method, I removed the bootstrap.setName("xdropwizard-service"); method as the setName method seems to have been removed from the API.

Since the XDropWizard webservice root URL was service, and the option to configure that was no longer available via the configuration file, I added the following line in the run method:

Resources

Adding resources to the application used to be done like this: environment.addResource(new YankBookResource());. The new way to do it looks like this: environment.jersey().register(new YankBookResource());.

Tasks

Adding tasks to the application used to be done like this: environment.addTask(new LockSundialSchedulerTask());. The new way to do it looks like this: environment.admin().addTask(new LockSundialSchedulerTask());.

Managed Objects

Adding tasks to the application used to be done like this: environment.manage(sm);. The new way to do it looks like this: environment.lifecycle().manage(sm);.

For a completeness, the Application class is pasted below.

Wrap Up

Migrating from DropWizard 0.6.x to 0.7.0 can be a bit tricky due to lack of an official migration guide. I hope some of the above examples are helpful to others.

Relevant Links

Related Posts

Subscribe To Our Newsletter

Join our low volume mailing list to receive the latest news and updates from our team.

Leave a Comment

Knowm 32X32 Crossbar

Knowm Newsletter

Are you ready for memristor AI processors? With our newsletter, you will be.