Skip to content

Instantly share code, notes, and snippets.

@dmorgantini
Last active August 13, 2020 20:09
Show Gist options
  • Save dmorgantini/11397642 to your computer and use it in GitHub Desktop.
Save dmorgantini/11397642 to your computer and use it in GitHub Desktop.
Dropwizard App with Admin Resource
public class TemplateApplication extends Application<ServiceConfiguration> {
public static void main(String[] args) throws Exception {
new TemplateApplication().run(args);
}
@Override
public void run(ServiceConfiguration configuration, Environment environment) throws Exception {
environment.jersey().register(new HelloWorldResource());
final DropwizardResourceConfig jerseyConfig = new DropwizardResourceConfig(environment.metrics());
JerseyContainerHolder jerseyContainerHolder = new JerseyContainerHolder(new ServletContainer(jerseyConfig));
jerseyConfig.getSingletons().add(new AdminResource());
environment.admin().addServlet("admin resources", jerseyContainerHolder.getContainer()).addMapping("/admin/*");
}
@Override
public void initialize(Bootstrap<ServiceConfiguration> bootstrap) {
}
}
@rajneeshpatel
Copy link

Used @ferdy-lw approach and worked fine with 1.0.5. As I have a separate admin context configured using the simple server config, used the mapping for the servlet as below to not conflict with the regular admin servlet.

environment.admin().addServlet("admin jersey resources", jerseyContainerHolder.getContainer()).addMapping("/admin/api/*");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment