As a developer that's what I expect sometimes, sometimes not ;). This
is really hard to handle all cases so there is no right solution ATM
(why spec addressed it).

javax.ejb.Singleton should be closet to what you are looking for,
deactivate the transactions and the overhead should be small enough to
be ignored compared to a cdi bean.

IIRC TomEE merges CDI beans from parent (lib part) and webapps so
instances are effectively different (it is like if webapp was
containing all libs which sounds close to what is in spec AFAIK but is
still ambiguous IMO). That is mandatory for frameworks like DS IIRC.

last note: you'll get same issue but @ApplicationScoped is preferred
over @Singleton since it is a normal scope (but that's maybe what you
wanted).
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2013/12/28 hasalex <[email protected]>:
> Hi,
>
> The question seems weird, but has been asked on the CDI dev issue tracker :
> issues.jboss.org/browse/CDI-226.
>
> I've tested it in TomEE, and it looks like that we can have multiple
> instances of a @Singleton in an EAR application. My example is here :
> https://github.com/hasalex/tomee-sample/blob/QuestionOnML/tomee-sample-war/src/test/java/fr/sewatech/javaee/example/SingletonTest.java
>
> The @Singleton injected in the EJB is different from the one injected in the
> SessionContextListener.
>
> As a developer, that was not what I was expecting. So am I wrong or is that
> Singleton behaviour strange ?
>
> Alexis
>
>
>
> --
> View this message in context: 
> http://openejb.979440.n4.nabble.com/What-is-the-scope-of-a-Singleton-CDI-bean-in-an-EAR-tp4666902.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.

Reply via email to