A typical DropWizard application specifies an Application subclass, and override its initialize method like so:
class MyApplication extends Application<MyConfiguration> {
static void main(String[] args) {
new MyApplication().run(args)
}
@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
// ???
}
@Override
public void run(MyConfiguration configuration, Environment environment)
throws Exception {
// Register resources, health checks, etc.
}
}
After perusing the DropWizard docs, as well as the JavaDocs for:
Configuration- An object representation of the YAML configuration file. Extend this with your own configuration properties, and they'll be parsed from the YAML file as well.Bootstrap- The pre-start application environment, containing everything required to bootstrap a Dropwizard command.Environment- A Dropwizard application's environment.
But these are rather vague class definitions, particularly the last two. I understand that I am supposed to subclass Configuration, and that it represents an in-memory POJO of my app's YAML/JSON config file.
But I can not understand what the other constructs represent (Bootstrap and Environment). I am used to injecting environment-specific configs into my apps, and so I tend to think of the concepts of "environment" and "configuration" as one in the same.
Furthermore, it seems DropWizard closely couples Bootstrap instances with Configuration impl instances, but I can find no demonstrable examples as to how these two classes are different, and how they should be used different from one another.
So I ask:
- What is a
Bootstrap, what do I use it for? - What is an
Environment, and what do I use it for?