Fork me on GitHub

Dropwizard Internals

You already read through the whole Dropwizard documentation? Congrats! Then you are ready to have a look into some nitty-gritty details of Dropwizard.

Startup Sequence

Below you find the startup sequence of a Dropwizard Application:

    1. new Bootstrap
    2. bootstrap.addCommand(new ServerCommand)
    3. bootstrap.addCommand(new CheckCommand)
    4. initialize(bootstrap) (implemented by your Application)
      1. bootstrap.addBundle(bundle)
        1. bundle.initialize(bootstrap)
      2. bootstrap.addCommand(cmd)
        1. cmd.initialize()
    5. new Cli(bootstrap and other params)
      1. for each cmd in bootstrap.getCommands()
        1. configure parser w/ cmd
      1. is help flag on cmdline? if so, print usage
      2. parse cmdline args, determine subcommand (rest of these notes are specific to ServerCommand)
      3., namespace) (implementation in ConfiguredCommand)
        1. parse configuration
        2. setup logging
      4., namespace, cfg) (implementation in EnvironmentCommand)
        1. create Environment
        2., env)
          1. for each Bundle:
          2. for each ConfiguredBundle:
        3., env) (implemented by your Application)
    7., namespace, cfg) (implemented by ServerCommand)
      1. starts Jetty

On Bundles

Running bundles happens in FIFO order (ConfiguredBundles are always run after Bundles).

Jetty Lifecycle

If you have a component of your app that needs to know when Jetty is going to start, you can implement Managed as described in the dropwizard docs.

If you have a component that needs to be signaled that Jetty has started (this happens after all Managed objects’ start() methods are called), you can register with the env’s lifecycle like:

env.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {
    public void serverStarted(Server server) {
              /// ... do things here ....