Migrating to Dropwizard version 0.8.0 was easier than the update from 0.6.x to 0.7.0, but there were still some hang ups, so I thought I would share some of the migration changes need for upgrading to the latest release of from version 0.7.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.
Default service URL
In the case where you want to change the default API base URL to something other than /
there is a setting for that. Previously it was set in Java code, and now it’s set in the YML config file. Below is a snippet from XDropWizard.
Before (Version 0.7.x)
1 2 3 4 5 6 7 8 |
@Override public void run(XDropWizardApplicationConfiguration configuration, Environment environment) throws Exception { environment.jersey().setUrlPattern("/service/*"); ... } |
After (Version 0.8.0)
1 2 3 4 5 6 7 8 9 |
server: type: simple rootPath: '/service/*' applicationContextPath: / adminContextPath: /admin connector: type: http port: 9090 ... |
ViewBundle
Before version 0.8.0, ViewBundle
was a concrete class and you could new-up an instance of it and be done. Now ViewBundle
is an abstract class so you need to new it up and implement it’s one abstract method. Below is a snippet from XDropWizard.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
@Override public void initialize(Bootstrap<XDropWizardApplicationConfiguration> bootstrap) { bootstrap.addBundle(new AssetsBundle("/assets/", "/")); bootstrap.addBundle(new ViewBundle<XDropWizardApplicationConfiguration>() { @Override public ImmutableMap<String, ImmutableMap<String, String>> getViewConfiguration(XDropWizardApplicationConfiguration configuration) { return ImmutableMap.of(); } }); bootstrap.addBundle(new SundialBundle<XDropWizardApplicationConfiguration>() { @Override public SundialConfiguration getSundialConfiguration(XDropWizardApplicationConfiguration configuration) { return configuration.getSundialConfiguration(); } }); } |
After commit 943, which is part of the 0.8.1 release, configuring the ViewBundle is straight-forward again:
1 |
bootstrap.addBundle(new ViewBundle<XDropWizardApplicationConfiguration>()); |
Wrap Up
Migrating from DropWizard 0.7.x to 0.8.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.
Subscribe To Our Newsletter
Join our low volume mailing list to receive the latest news and updates from our team.