users@glassfish.java.net

Re: _at_Startup _at_Singleton injection behavior question

From: Noah White <emailnbw_at_gmail.com>
Date: Tue, 5 Feb 2013 18:10:49 -0500

Hi Marina,

Nothing fancy along those lines is going on here. This @ApplicationScoped bean is simply responsible for providing some preferences which it initializes in its @PostConstruct. It is injected all over the place, including in this @Startup @Singleton. As a test I disable the EJB and observed the @PostConstruct method on the CDI bean is called when it is being injected into a ServletContextListener so I don't think that is the case. It feels like it is I think this is EJB/CDI lifecycle related.

-Noah

On Feb 5, 2013, at 5:37 PM, Marina Vatkina <marina.vatkina_at_oracle.com> wrote:

> May be PostConstruct interceptor is not enabled for the CDI bean?
>
> -marina
> On 2/5/13 2:26 PM, Noah White wrote:
>> I have a @Startup @Singleton EJB which injects an @ApplicationScoped CDI bean which is used by the EJB's @PostConstruct method. It calls a getter on this @ApplicationScoped bean and is getting back NULL.
>>
>> What's interesting is the object returned by the @ApplicationScoped bean's getter is constructed in its @PostConstruct method. It appears @PostConstruct is not being called in this case. The @ApplicationScoped bean itself does not inject any resources.
>>
>> Is this a bug or by design? If by design could you point me to the spec reference? Thanks,
>>
>> -Noah
>>
>> Environment is gf: 3.1.2 b23
>