users@glassfish.java.net

Re: GF V3 - Cannot resolve reference Remote ejb-ref

From: <glassfish_at_javadesktop.org>
Date: Tue, 26 Jan 2010 06:30:22 PST

Thanks for attaching the ear and the sources for us to look at.

    Looking at the current packaging, the DemoServiceSecondBean was packaged in both ejb jars (included directly in the jee-demo-lib-0.0.2-SNAPSHOT.jar and included in-directly through the ejb-jar.xml in the jee-demo-ejb-0.0.2-SNAPSHOT.jar). And the AppServiceOneBean which references this bean is packaged in jee-demo-ejb-0.0.2-SNAPSHOT.jar.

     This is how the AppServiceOneBean references this EJB currently:
        @EJB
        DemoServiceSecond demoServiceSecond;

      As it did not provide any additional information of this EJB reference other than the bean interface name, the ejb reference resolving code is trying to match with all the classes which implements this interface and it found two (one in each ejb jar) so it does not know which one it means and the deployment fails.

      I understand you need this packaging for your particular reason, and you don't want to change how the beans are packaged, so to solve this, you can try to provide additional information to the ejb reference so it has some extra clue to figure out which bean it really wants to reference.

      There is a beanName attribute of the @EJB annotation that can be used to link the ejb reference to a particular bean and you can take advantage of that.
 
       So in your AppServiceOneBean, you can reference the EJB with an explicit beanName:
        @EJB(beanName="myDemoServiceSecondBean")
        DemoServiceSecond demoServiceSecond;

     And in the META-INF/ejb-jar.xml of jee-demo-ejb-0.0.2-SNAPSHOT.jar, you declare the Bean included in this ejb jar with this name:
 <enterprise-beans>
                <session>
                        <ejb-name>myDemoServiceSecondBean</ejb-name>
                        <ejb-class>org.imixs.demo.DemoServiceSecondBean</ejb-class>
                        <session-type>Stateless</session-type>
                </session>
        </enterprise-beans>
 
    This way, the ejb reference in AppServiceOneBean should be able to resolve unambiguously (AppServiceOneBean will be referencing the DemoServiceSecondBean class which is packaged in the same ejb jar).

    Please give this a try and let us know if it works for you. Thanks.
[Message sent by forum member 'hzhang_jn' (hong.zhang_at_sun.com)]

http://forums.java.net/jive/thread.jspa?messageID=383026