users@jersey.java.net

Re: [Jersey] Resource autoscan despite the existence of an Application class

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Thu, 12 Aug 2010 10:37:59 +0200

On Aug 11, 2010, at 9:44 PM, Christian Helmbold wrote:

> The autoscan for resource classes works fine as long as I don't
> specify my own
> JAX-RS application class in the web.xml. Then I have to list all the
> class
> manually in the class. But I want only perform some initialisation
> in the
> constructor.
>
> How can I use the autoscan AND provider my own Application class?
>

Your application can extend from PackagesResourceConfig.

   https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/core/PackagesResourceConfig.html

If you do something like this:

    public class MyApp extends PackagesResourceConfig {
      public MyApp(Map<String, String> props) {
         super(props);
         ...
      }
    }

then the init params defined in the web.xml will be taken into
account. Otherwise you can choose to declare the package names using
the other constructor.

Paul.