Last active
August 13, 2020 20:09
-
-
Save dmorgantini/11397642 to your computer and use it in GitHub Desktop.
Dropwizard App with Admin Resource
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
} | |
} |
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
as a person who recently hit into this issue - need to configure Admin space servlet, I recommend using https://github.com/xvik/dropwizard-guicey which can automatically wire up your annotated servlets