users@jersey.java.net

Re: [Jersey] Custom Configuration in Jersey App - where to put

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 03 Sep 2009 09:59:38 +0200

On Sep 3, 2009, at 1:06 AM, saturon wrote:

> Hi there,
>
> Where is the best place to put custom global configuration (like
> mail host, email senders, etc.) of a jersey webapp (running inside
> GF v2) ?
>
> Database is not an option.
>
> Would like it to be file based that can be changed without
> recompiling, just redeploy.
>
> AFAIK web.xml init-params are not accessible from Jersey. Is this
> still the case with the latest releases?
>
>

The init params are available as properties of ResourceConfig. So you
can inject that:

   @Context ResourceConfig rc;

Or you can inject the ServletConfig:

   @Context ServletConfig sc;

to get direct access to those parameters. The nice thing about using
ResourceConfig is that it abstracts from Servlet or Filter deployment.


Another approach could be to have properties in a java properties file
and implement an injectable provider that injects an instance of
java.util.Properties, for example:

   @PropertiesRef("WEB-INF/mail") Properties p;

or another approach is to do something similar using JavaBeans with
XML decoding/encoding, or extracting values from init-params based on
the bean name.

Let me know if you want more details on this,
Paul.