tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gurkan Erdogdu <gerdo...@managecat.com>
Subject Re: Two beans with the same name - I thought was supposed to give error?
Date Wed, 16 Sep 2015 09:20:50 GMT
Hello Colin

This is not related with CDI, you are using @Stateful annotation defined in EJB specification.
EJB names are used to give a unique name to EJB beans, therefore you can inject them via @EJB(name
of the bean). In OpenEJB, you can use the same name here but name will be used for EJB bean
first deployed. If Movies2 will be deployed first, only this bean is deployed otherwise Movies
will be deployed and created JNDI name for them. According to EJB specification, The ejb-name
element contains the name of an enterprise
bean. The name must be unique within the ejb-jar file.	Therefore, you have to give unique
names to EJB beans.

So, if you want to use Alternative with CDI specification, you can use @Inject to inject EJB
Beans and use @Alternatives to describe alternative CDI beans and also define alternatives
in beans.xml.

Please have a look at this example : https://github.com/apache/tomee/tree/master/examples/cdi-alternative-and-stereotypes
<https://github.com/apache/tomee/tree/master/examples/cdi-alternative-and-stereotypes>


Hope that it helps!

Best
Gurkan Erdogdu
ManageCat, http://www.managecat.com <http://www.managecat.com/> 
Office : +1 (909) - 366 – 9337
340 S Lemon Ave #7996 Walnut, CA 91789

One of them is : 

> On 16 Sep 2015, at 07:54, cfnz <reg@hill-labs.co.nz> wrote:
> 
> Still trying to come to grips with beans and CDI, etc...
> 
> I was under the impression that if two beans had the same name, that the
> container would complain as it would not know which one to use... but it
> doesn't... is it supposed to?
> 
> Test case... take the eclipse link movies example, copy Movies.java to
> Movies2.java and add the following:
> 
> @Stateful(name = "Movies")
> public class Movies2 {
> ... etc
> }
> 
> I thought this would complain... When the test case asks for Movies, how
> does it know which movies it will get?? I have been looking into the
> @Alternative annotation, but the first thing I need to sort out is why the
> above works... (I have another query on how to select the @Alternative, but
> I shall do another post for that.)
> 
> Regards
> Colin
> 
> 
> 
> 
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/Two-beans-with-the-same-name-I-thought-was-supposed-to-give-error-tp4676235.html
> Sent from the TomEE Users mailing list archive at Nabble.com.








Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message