Add jetty servlet into dropwizard

旧巷老猫 提交于 2019-12-08 16:49:06

问题


I need to add jetty servlet into my already existing server implemented using dropwizard framework.

To be more specific:

  1. I have a restful resource Foo mapped to url "localhost:8080/foo" with CRUD operations.
  2. Now I need a jetty servlet mapped to url "localhost:8080/bar" and handles all requests to this url (mainly GET and POST).

I could not get a clue how to do this after some googlings. Could someone please give me a direction or a snippet? Thanks!


回答1:


If you're using Dropwizard 0.6.2 you should be able to do something like this in your run method:

ServletBuilder builder = environment.addServlet(myServlet, "/bar");

If you're using Dropwizard 0.7.0 try this:

environment.getApplicationContext().addServlet("org.example.MyServlet", "/bar");



回答2:


For 0.7.0 you have the ServletEnvironment and a couple of ways to add servlets. For example:

@Override
public void run(ApplicationConfiguration configuration, Environment environment) throws Exception {
    environment.servlets().addServlet("foo", MySerlvet.class).addMapping("/bar");
}

Incidentally, you also have the AdminEnvironment, which is an extension of ServletEnvironment and any servlets added to this in the same way would accessible on /admin/bar.



来源:https://stackoverflow.com/questions/23239218/add-jetty-servlet-into-dropwizard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!