Core components of the Dropwizard framework for building Java web applications
npx @tessl/cli install tessl/maven-io-dropwizard--dropwizard-core@4.0.00
# Dropwizard Core
1
2
Dropwizard Core provides the fundamental building blocks for creating production-ready Java web applications. It combines Jetty, Jersey, Jackson, and other proven libraries into a cohesive framework that enables rapid development of RESTful web services with built-in metrics, logging, health checks, and operational features.
3
4
## Package Information
5
6
- **Package Name**: io.dropwizard:dropwizard-core
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**: Add to Maven `pom.xml`:
10
```xml
11
<dependency>
12
<groupId>io.dropwizard</groupId>
13
<artifactId>dropwizard-core</artifactId>
14
<version>4.0.14</version>
15
</dependency>
16
```
17
18
## Core Imports
19
20
```java
21
import io.dropwizard.core.Application;
22
import io.dropwizard.core.Configuration;
23
import io.dropwizard.core.setup.Bootstrap;
24
import io.dropwizard.core.setup.Environment;
25
```
26
27
## Basic Usage
28
29
```java
30
import io.dropwizard.core.Application;
31
import io.dropwizard.core.Configuration;
32
import io.dropwizard.core.setup.Bootstrap;
33
import io.dropwizard.core.setup.Environment;
34
35
public class HelloWorldApplication extends Application<HelloWorldConfiguration> {
36
public static void main(String[] args) throws Exception {
37
new HelloWorldApplication().run(args);
38
}
39
40
@Override
41
public String getName() {
42
return "hello-world";
43
}
44
45
@Override
46
public void initialize(Bootstrap<HelloWorldConfiguration> bootstrap) {
47
// Add bundles to bootstrap
48
}
49
50
@Override
51
public void run(HelloWorldConfiguration configuration, Environment environment) {
52
// Register resources, health checks, tasks, etc.
53
final HelloWorldResource resource = new HelloWorldResource(
54
configuration.getTemplate(),
55
configuration.getDefaultName()
56
);
57
environment.jersey().register(resource);
58
}
59
}
60
61
public class HelloWorldConfiguration extends Configuration {
62
@NotEmpty
63
private String template = "Hello, %s!";
64
65
@NotEmpty
66
private String defaultName = "Stranger";
67
68
@JsonProperty
69
public String getTemplate() {
70
return template;
71
}
72
73
@JsonProperty
74
public void setTemplate(String template) {
75
this.template = template;
76
}
77
78
@JsonProperty
79
public String getDefaultName() {
80
return defaultName;
81
}
82
83
@JsonProperty
84
public void setDefaultName(String name) {
85
this.defaultName = name;
86
}
87
}
88
```
89
90
## Architecture
91
92
Dropwizard Core is built around several key components:
93
94
- **Application Lifecycle**: `Application` class serves as the main entry point with configurable bootstrapping and runtime phases
95
- **Configuration Management**: YAML-based configuration with type-safe binding via Jackson and Bean Validation
96
- **Environment Abstraction**: `Environment` class provides unified access to Jersey, servlet, admin, lifecycle, and health subsystems
97
- **Command-Line Interface**: Extensible CLI system with built-in server and configuration check commands
98
- **Server Factories**: Pluggable server implementations (Default multi-connector, Simple single-connector)
99
- **Bundle System**: Reusable application components that can be registered during bootstrap
100
101
## Capabilities
102
103
### Core Application Framework
104
105
Essential classes for building Dropwizard applications including the main Application class, Configuration base class, and Bootstrap setup.
106
107
```java { .api }
108
public abstract class Application<T extends Configuration> {
109
public abstract void run(T configuration, Environment environment) throws Exception;
110
public void initialize(Bootstrap<T> bootstrap);
111
public void run(String... arguments) throws Exception;
112
}
113
114
public class Configuration {
115
public ServerFactory getServerFactory();
116
public LoggingFactory getLoggingFactory();
117
public MetricsFactory getMetricsFactory();
118
public AdminFactory getAdminFactory();
119
public Optional<HealthFactory> getHealthFactory();
120
}
121
```
122
123
[Core Application Framework](./core-application.md)
124
125
### Environment and Setup
126
127
Environment management providing access to Jersey, servlet container, admin interface, lifecycle management, and health checks.
128
129
```java { .api }
130
public class Environment {
131
public JerseyEnvironment jersey();
132
public ServletEnvironment servlets();
133
public AdminEnvironment admin();
134
public LifecycleEnvironment lifecycle();
135
public HealthEnvironment health();
136
public MetricRegistry metrics();
137
public HealthCheckRegistry healthChecks();
138
}
139
140
public class Bootstrap<T extends Configuration> {
141
public void addBundle(ConfiguredBundle<? super T> bundle);
142
public void addCommand(Command command);
143
public MetricRegistry getMetricRegistry();
144
public ObjectMapper getObjectMapper();
145
}
146
```
147
148
[Environment and Setup](./environment-setup.md)
149
150
### Command-Line Interface
151
152
Extensible command-line interface system with built-in commands for server management and configuration validation.
153
154
```java { .api }
155
public abstract class Command {
156
public Command(String name, String description);
157
public abstract void configure(Subparser subparser);
158
public abstract void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception;
159
}
160
161
public abstract class ConfiguredCommand<T extends Configuration> extends Command {
162
protected abstract void run(Bootstrap<T> bootstrap, Namespace namespace, T configuration) throws Exception;
163
}
164
```
165
166
[Command-Line Interface](./cli.md)
167
168
### Server Configuration
169
170
Pluggable server factory system supporting different deployment patterns with configurable connectors and thread pools.
171
172
```java { .api }
173
public interface ServerFactory extends Discoverable {
174
Server build(Environment environment);
175
void configure(Environment environment);
176
}
177
178
public class DefaultServerFactory extends AbstractServerFactory {
179
// Multi-connector server supporting separate application and admin ports
180
}
181
182
public class SimpleServerFactory extends AbstractServerFactory {
183
// Single-connector server combining application and admin on same port
184
}
185
```
186
187
[Server Configuration](./server-config.md)
188
189
### Bundle System and SSL Reload
190
191
Reusable application components and built-in bundles for common functionality like SSL certificate reloading.
192
193
```java { .api }
194
public interface ConfiguredBundle<T> {
195
default void run(T configuration, Environment environment) throws Exception;
196
default void initialize(Bootstrap<?> bootstrap);
197
}
198
199
public class SslReloadBundle implements ConfiguredBundle<Configuration> {
200
// Provides SSL certificate reloading capability via admin task
201
}
202
```
203
204
[Bundle System](./bundles.md)
205
206
## Common Types
207
208
```java { .api }
209
// Base configuration class
210
public class Configuration {
211
@Valid @NotNull
212
private ServerFactory server = new DefaultServerFactory();
213
214
@Valid @Nullable
215
private LoggingFactory logging;
216
217
@Valid @NotNull
218
private MetricsFactory metrics = new MetricsFactory();
219
220
@Valid @NotNull
221
private AdminFactory admin = new AdminFactory();
222
223
@Valid @Nullable
224
private HealthFactory health;
225
}
226
227
// ConfiguredBundle interface for reusable components
228
public interface ConfiguredBundle<T> {
229
default void run(T configuration, Environment environment) throws Exception;
230
default void initialize(Bootstrap<?> bootstrap);
231
}
232
233
// Server factory interface for pluggable server implementations
234
public interface ServerFactory extends Discoverable {
235
Server build(Environment environment);
236
void configure(Environment environment);
237
}
238
```