users@glassfish.java.net

Re: [Asking]About HK2 Construtor Injection

From: John Wells <john.wells_at_oracle.com>
Date: Wed, 27 Feb 2013 09:14:23 -0500

This is because hk2 2.0 uses the standard @Inject which cannot be placed
on parameters. Your constructor would have to change to look like this:

@Inject
public LocalServerPoolFactory(TemplateRepository
                                      templateRepository,
                              Domain domain,
                              ServerContext environment) {
        this.templateRepository = templateRepository;
        this.domain = domain;
        this.environment = environment;
}



On 2/27/2013 8:32 AM, Tang Yong wrote:
> Hi Jwells, Team
>
> I have another question about HK2 Construtor Injection.
>
> Currently, because of a fact that org.jvnet.hk2.annotations.Inject has
> been changed into javax.inject.Inject(JSR330 spec), the following
> Construtor Injection seemed to have problem,
>
> public LocalServerPoolFactory(@Inject TemplateRepository
> templateRepository,
> @Inject Domain domain,
> @Inject ServerContext environment) {
> this.templateRepository = templateRepository;
> this.domain = domain;
> this.environment = environment;
> }
>
> In constructor, @Inject seemed to be not allowed there.
>
> So, I want to know whether there are something with me?
>
> Thanks
> --Tang
>