users@jersey.java.net

Re: [Jersey] How to access init-param values from a Jersey web application

From: Martin Giese <martingi_at_ifi.uio.no>
Date: Thu, 20 May 2010 15:09:10 +0200

On 05/20/2010 03:02 PM, Paul Sandoz wrote:
>
>>> Yes, it should be possible to do the following:
>>>
>>> public MyApp extends Application {
>>> @Context ServletConfig sc;
>>> }
>> I tried that. When I read sc in the constructor, it's null.
>>
>
>
> Yes, that is because field injection occurs after construction. You
> need to use a @PostConstruct annotated method to access such values.
>
Like this?

public class MyApp extends PackagesResourceConfig {
    @Context ServletConfig sc;
   
    public AddressFetcher() {
        super("no.uio.ifi.martingi.addresses");
    }

    @PostConstruct
    public void readInitParams() {
       
//System.out.println(sc.getInitParameter("no.uio.ifi.martingi.addresses.userid"));
   
        System.out.println(sc);
    }
}

The @PostConstruct method is not called :-(

Martin