users@glassfish.java.net

Re: EJB with constructor injection not working in servlet

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Fri, 04 Nov 2011 15:35:00 -0700

We have a devtest that uses arg constructor for a singleton:
http://svn-mirror.glassfish.org/glassfish-svn/trunk/v2/appserv-tests/devtests/ejb/ejb31/full/jcdifull/ejb/SingletonBean2.java
though that arg is injected by CDI...

-marina

forums_at_java.net wrote:
> I was dimly aware that EJBs must have a no-arg constructor, thanks for
> pointing me to it with a reference :-) [small typo, the section in the
> EJB
> spec [1] is 4.9.2, not 3.9.2]
>
> BUT:
>
> 1) The CDI spec [2] says at the start of section 3 that Session beans are
> supported by CDI. Section 3.2 then talks at length about CDI and EJBs but
> never mentions anything about constructor injection not working.
> This is why I believe that is should work. Some googling turned up one
> or two
> forum posts saying that CDI constructor injection should work for
> EJBs, but
> nothing authoritative.
>
> I would much appreciate an authoritative statement either way.
>
> 2) As described above in several cases constructor injection does work
> with
> EJBs:
>
> * with an additional no-argument constructor to GreeterEjb (I wonder
> what
> happens internally...)
> * with an Interface GreeterInterface (see code below). GreeterEjb
> implements
> GreeterInterface. In InjectedServlet changed type of field
> greeterEjb from
> GreeterEjb to GreeterInterface
> * *new: *when in InjectedServlet @Inject is replaced with @EJB
>
>
> If CDI constructor injection for EJBs were not allowed by the spec, then
> these would all be (undocumented?) Glassfish extensions?
>
> Best regards,
> Arend
>
>
> [1] http://jcp.org/en/jsr/detail?id=318
> [2] http://jcp.org/en/jsr/detail?id=299
>
> --
>
> [Message sent by forum member 'arendvr.com']
>
> View Post: http://forums.java.net/node/860661
>
>