users@jersey.java.net

Re: [Jersey] Testing with init-params

From: Edwin Shin <eddie_at_fedora-commons.org>
Date: Thu, 20 May 2010 14:18:00 +0200

Paul,

mea culpa. In my fantasy land I was trying to access ServletConfig without passing it in as a constructor argument:

class Foo {
  @Context ServletConfig sc;
  public Foo() {
    sc.getInitParameter("bar");
  }
}

Thanks again,
Eddie

On 19 May 2010, at 5:48 PM, Paul Sandoz wrote:

>
> On May 18, 2010, at 2:27 AM, Edwin Shin wrote:
>
>> Pavel,
>>
>> Thanks for your response. Your test case works for me as well. When I was trimming down the code excerpts to include in my original email, I changed what was originally a constructor into a regular method call.
>>
>> But it was in fact in a constructor that I was trying to access the init-params from ServletConfig. Am I right to understand that this is not possible? I seem to recall having read that the context injection was available to constructors, so I didn't think more of it at the time.
>>
>
> Constructor injection is supported. Can you share the code?
>
> I modified Pavel's test csae and it worked fine doing:
>
> public TestResource(@Context ServletConfig servletConfig) {
> assert(servletConfig != null);
> }
>
>
>> I worked around this by using a @PostConstruct method where I grabbed the init-params I needed for object construction. Would this be the recommended way to get at the init-params for object construction?
>>
>
> IMHO constructor injection is more preferable if you can use a constructor.
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>