users@jersey.java.net

[Jersey] Re: How to init a static Porperties instance using the ServletContext?

From: John Lister <john.lister_at_kickstone.com>
Date: Tue, 24 May 2011 07:34:21 +0100

On 19:59, exxos wrote:
> Hi,
>
> I need to read parameters from ServletContext (for example, the
> parameters declared in the Context.xml or the Web.xml of the WebApp).
> Once read, these parameters have to be shared as global parameters for
> the WebApp.
>
> To get this, I used the injection @Context ServletContext
> servletContext and I created a static instance of java.util.Properties
> (wrapped in a dedicated PropertiesLoader class).
>
> This works quite well except that I do not know where and when to call
> the method that is in charge to initialize the static instance of
> java.util.Properties (using the the ServletContext).
>
> This issue is because I have several independant Resources (@path
> /resrouce) and all these resources need to refer the static Properties.
>
> My question is:
> Is there a proper solutions (with Jersey?) to call the init process at
> the start up (or the deployment) of the WebApp before exposing all
> Resources?
I would think creating either an @ApplicationScoped bean or a singleton
ejb would answer your problem. you could place the properties within the
bean and also inject the servletcontext in order to fill the properties.

John