Quick revision
The short answer
A Dropwizard application is a class that extends Application<MyConfiguration>. In initialize(Bootstrap) we add bundles and commands before the configuration is read, and in run(configuration, environment) we register Jersey resources, health checks and managed objects. MyConfiguration extends Configuration and is filled from the YAML file by Jackson, then validated by Hibernate Validator. Running java -jar app.jar server config.yml parses and validates that file, calls run, and starts Jetty with an application connector, by default on port 8080, and an admin connector on port 8081.
What to remember
In this answer, we saw that a Dropwizard application consists of a Configuration subclass mapped from YAML by Jackson and validated by Hibernate Validator, an Application subclass with initialize for bundles and commands and run for resources, health checks and managed objects, a Bootstrap used before the configuration is read and an Environment used after. Running the server command reads and validates config.yml, runs the bundles and our run method, and starts Jetty with the application connector on 8080 and the admin connector on 8081, while check and bundle commands such as db migrate reuse the same jar and configuration.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A Dropwizard application is a class that extends Application<MyConfiguration>. In initialize(Bootstrap) we add bundles and commands before the configuration is read, and in run(configuration, environment) we register Jersey resources, health checks and managed objects. MyConfiguration extends Configuration and is filled from the YAML file by Jackson, then validated by Hibernate Validator. Running java -jar app.jar server config.yml parses and validates that file, calls run, and starts Jetty with an application connector, by default on port 8080, and an admin connector on port 8081.
Why this question is asked
Dropwizard is a lean, opinionated framework for REST services that bundles Jetty, Jersey, Jackson, Hibernate Validator and Dropwizard Metrics into one runnable jar. Many companies still run services built on it, and its structure is small enough to understand completely, which is why interviewers ask about it. Knowing exactly what happens at startup is also what lets us debug a service that refuses to start. In this answer, we will look at the four core classes, write a minimal application, follow the server command step by step, and see the other commands available.
1The Four Core Pieces
Dropwizard is built around four types. The Configuration subclass is a plain Java class whose fields mirror the YAML configuration file. The Application subclass is the entry point that wires everything together. The Bootstrap is the setup object available before configuration is loaded, where bundles, commands and configuration sources are registered. And the Environment is the runtime object, available once the configuration is known, that gives access to Jersey, the servlet container, the admin interface, metrics, health checks and lifecycle.
The split between Bootstrap and Environment follows from the order of startup. Some things, such as which commands exist or how to read the configuration file, must be decided before the file is read. Others, such as a resource that needs a database URL, can only be built after it.
2A Minimal Application
Here is a small but complete application with a configuration value, one resource and one health check.
Notice that the resource is a plain JAX-RS class. Jersey, the JAX-RS implementation inside Dropwizard, handles the routing and Jackson writes the response. In Dropwizard 4 and later the JAX-RS and validation annotations come from the jakarta packages; in older versions they were javax.
3What Happens When We Run the Server Command
The command java -jar app.jar server config.yml starts main, which calls run(args). Dropwizard reads the first argument as the name of a command and the second as the configuration file.
- Application.initialize(bootstrap)bundles, commands, config source
- Read config.ymlJackson maps YAML onto
HelloConfiguration - Valid configuration?YesBuild the EnvironmentNoPrint the errors and exit
- Bundles' run, then Application.runregister resources, health checks, managed
- Start Jettyapplication port 8080, admin port 8081
- Start managed objectsthen accept requests
6 steps in order. Play them, or step through them one at a time.
Validation happens before our run method, so a bad config never starts a half-working service.
Step by step: Dropwizard first calls initialize with the Bootstrap, so bundles and commands are registered. It then finds the server command, reads config.yml through the configuration source provider, and asks Jackson to map the YAML onto HelloConfiguration. Hibernate Validator checks the annotations, here @NotEmpty; if validation fails, the application stops before anything else runs and prints which field is wrong. Next it builds the Environment, runs each bundle's run method, then our run method. Finally it builds and starts Jetty with the configured connectors, starting managed objects along with it.
4The Environment and the Admin Connector
Inside run, the Environment is our toolbox. environment.jersey() registers resources, filters and exception mappers. environment.healthChecks() registers health checks, which extend HealthCheck and return healthy or unhealthy with a message. environment.metrics() gives the Dropwizard Metrics registry. environment.lifecycle() manages objects with start and stop, and builds executors that are shut down with the server. environment.servlets() and environment.admin() give access to the servlet contexts.
The admin connector on port 8081 exposes operational endpoints separate from the application: health checks under /healthcheck, metrics under /metrics, thread dumps and a ping endpoint, plus tasks we can trigger with POST requests. Keeping them on a separate port means a firewall can expose 8080 to clients while 8081 stays internal, which is one of Dropwizard's production-ready defaults.
5Other Commands: check and Bundle Commands
server is not the only command. check reads and validates the configuration file and exits without starting Jetty, which is useful in a deployment pipeline to reject a broken config before rollout. Bundles can add commands: the MigrationsBundle from dropwizard-migrations adds db commands, so java -jar app.jar db migrate config.yml runs Liquibase migrations with the database settings from the same file. We can also write our own Command or ConfiguredCommand and add it in initialize.
So the jar is a small command-line tool as well as a server, which keeps operational tasks in the same artefact and configuration as the service.
6Follow-up questions
Why does Dropwizard put the admin endpoints on a different port?
To separate operational traffic from application traffic. Health checks, metrics and thread dumps should not be reachable by clients, and on a separate port they can be firewalled differently. It also means the admin endpoints stay available when the application thread pool is saturated.
What is the difference between a bundle and a command?
A bundle is reusable setup code that hooks into initialize and run, for example to register assets, Hibernate or migrations. A command is something the jar can do from the command line, such as server, check or db migrate. A bundle can add commands, which is how MigrationsBundle provides the db commands.
Can Dropwizard run with a single port?
Yes. The simple server factory, configured with server type simple, serves the application and admin contexts on one connector under different path prefixes. It suits environments where only one port is convenient, such as some container platforms.
7Conclusion
In this answer, we saw that a Dropwizard application consists of a Configuration subclass mapped from YAML by Jackson and validated by Hibernate Validator, an Application subclass with initialize for bundles and commands and run for resources, health checks and managed objects, a Bootstrap used before the configuration is read and an Environment used after. Running the server command reads and validates config.yml, runs the bundles and our run method, and starts Jetty with the application connector on 8080 and the admin connector on 8081, while check and bundle commands such as db migrate reuse the same jar and configuration.
Open with
A Dropwizard service has four main pieces. I write a configuration class that extends Configuration, whose fields match the YAML file; Jackson maps the file onto it and Hibernate Validator checks its annotations.
Then, if they want more
My application class extends Application of that configuration type and overrides two methods. initialize receives the Bootstrap, which exists before the configuration is read, so that is where I add bundles, commands or a custom configuration source. run receives the validated configuration and the Environment, and there I register Jersey resources with environment.jersey().register, health checks, managed objects through environment.lifecycle(), and metrics.
When I run java -jar app.jar server config.yml, Dropwizard calls initialize, picks the server command, reads and parses config.yml, and validates it; if a field is invalid it prints the error and exits before anything starts.
Then it builds the Environment, runs each bundle's run and then mine, and starts Jetty with the application connector, by default on 8080, and the admin connector on 8081, which serves health checks, metrics, thread dumps and tasks. Managed objects start with the server.
Other commands include check, which only validates the configuration, handy in a pipeline, and commands added by bundles, like db migrate from the migrations bundle.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Describe the structure of a Dropwizard application: the Application class...": https://scrivio-interview-library.netlify.app/java/dropwizard/70f1e53ae0/