1

I know I can register resources in dropwizard like environment.jersey().register(new MyResource());

But if I have like 10+ or 20+ resource classes, it seems extremely inefficient to write 20+ lines. Is there a way to register all the classes in a module.

Googling for it reveal much. Any pointers to either docs or examples would be helpful.

Thanks,

AtharvaI
  • 1,160
  • 3
  • 16
  • 27
  • like this? http://stackoverflow.com/questions/520328/can-you-find-all-classes-in-a-package-using-reflection – user1419950 Mar 03 '16 at 21:50
  • An alternative way, if you add guicey to your setup, you get guice support + package scan + so-called installers that not only register the resources for you, but also all the filters and features that you may or may not have. https://github.com/xvik/dropwizard-guicey – pandaadb Mar 04 '16 at 10:10
  • good options :thumbsup: – AtharvaI Mar 04 '16 at 16:25

1 Answers1

4

You can use package scanning:

environment.jersey().packages(Class1.class.getPackage().getName(), "my.package2")

The documentation from io.dropwizard.jersey.setup.JerseyEnvironment:

/**
 * Adds array of package names which will be used to scan for components. Packages will be
 * scanned recursively, including all nested packages.
 *
 * @param packages array of package names
 */
public void packages(String... packages)
Meiko Rachimow
  • 4,664
  • 2
  • 25
  • 43