-
1. Re: BeanManager.getBeans() and EJBs
atomicknight Jul 1, 2012 10:11 PM (in response to ron_sigal)Section 4.9.7 of the EJB 3.1 specification defines how client views are determined for EJBs. Because your EJB implements a single interface, the EJB is assumed to have a single client view, which is the local interface EJBBookReader. Therefore, EJBBookReaderImpl does not exist as a bean type because it is not a client view of the EJB.
Now, this should work if you modify the definition of EJBBookReaderImpl to be the following:
{code}
@Stateful
@Local(EJBBookReader.class)
@LocalBean
@Provider
public class EJBBookReaderImpl implements EJBBookReader { ... }{code}
However, what you probably should be doing instead is looking up the EJB by interface:
{code}System.out.println(beanManager.getBeans(EJBBookReader.class));{code}
-
2. Re: BeanManager.getBeans() and EJBs
ron_sigal Jul 3, 2012 8:15 PM (in response to atomicknight)Hi Abraham,
Thank you so much for jumping in. Just to expand on your answer, I see that Section 3.2.2 "Bean types of a session bean" of the CDI doc, "JSR-299: Contexts and Dependency Injection forthe Java EE platform" says
"The unrestricted set of bean types for a session bean contains all local interfaces of the bean and their superinterfaces. If
the session bean has a bean class local view, the unrestricted set of bean types contains the bean class and all superclasses."
I'm still curious about two things.
1. Why does BeanManager.getBeans(Object.class) return
[... Session bean [class org.jboss.resteasy.ejb.EJBBookReaderImpl with qualifiers [@Any @Default]; local interfaces are [EJBBookReader] ...]
2. Something else a little interesting is happening. The interface EJBBookReader is defined
@Local
@Provider
@Consumes("application/test+xml")
public interface EJBBookReader extends MessageBodyReader<Book>
{ ... }
and I gave the definition of EJBBookReaderImpl above. When ResteasyCdiExtension processes EJBBookReaderImpl, it puts it in the application scope, but it ignores EJBBookReader. However, the output of
System.out.println(beanManager.getBeans(EJBBookReader.class).iterator().next().getScope());
is
interface javax.enterprise.context.ApplicationScoped
It seems that Weld is, in a sense, conflating EJBBookReader and EJBBookReaderImpl. I don't see anything in the CDI doc that supports this behavior. Just curious.
Thanks,
Ron
-
3. Re: BeanManager.getBeans() and EJBs
atomicknight Jul 3, 2012 10:47 PM (in response to ron_sigal)1 of 1 people found this helpful{quote}1. Why does BeanManager.getBeans(Object.class) return
[... Session bean [class org.jboss.resteasy.ejb.EJBBookReaderImpl with qualifiers {noformat}[@Any @Default]{noformat}; local interfaces are {noformat}[EJBBookReader]{noformat} ...]{quote}
This is actually specified in the sentence immediately following your quote from section 3.2.2:
{quote}In addition, java.lang.Object is a bean type of every session bean.{quote}
{quote}It seems that Weld is, in a sense, conflating EJBBookReader and EJBBookReaderImpl.{quote}
I think you might be confusing the concept of a "bean" with that of a "bean type." You apply a scope like @ApplicationScoped to a bean (implementation), but you access the bean via one of its bean types. In most cases, the implementation is itself one of the bean types, but this is not always the case (like in this scenario).
-
4. Re: BeanManager.getBeans() and EJBs
ron_sigal Jul 3, 2012 11:21 PM (in response to atomicknight)Curious thing 1:
Abraham Lin wrote:
I think you might be confusing the concept of a "bean" with that of a "bean type."
Yep, I think that's the answer. As you said, EJBBookReaderImpl does not exist as a bean type. However, THERE IS a Bean<?> EJBBookReaderImpl with bean type Object. Thanks.
Curious thing 2:
Abraham Lin wrote:
You apply a scope like @ApplicationScoped to a bean (implementation), but you access the bean via one of its bean types. In most cases, the implementation is itself one of the bean types, but this is not always the case (like in this scenario).
Ah. So BeanManager.getBeans(EJBBookReader.class) is returning the Bean<?> for EJBBookReaderImpl, which has application scope. I see.
Again, thank you so much.
-Ron