开发者

glassfish 3.1 jdni lookup on EJB3

I have the following Interfaces MyLocalBean, MyRemoteBean and the stateless MyBean implements MyLocalBean, MyRemoteBean Which of the following i don't need to get a simple java application to test this ...

ejb-jar.xml, glassfish-ejb-jar.xml, gf-client.jar

Here's ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
   <enterprise-beans>
      <session>
         <ejb-name>MyEJB</ejb-name>
         <home>test.ejb.MyLocalBean</home>
         <remote>test.ejb.MyRemoteBean</remote>
         <ejb-class>test.ejb.MyBean </ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Container</transaction-type>
      </session>
   </enterprise-beans>
</ejb-jar>

what's missing here? would i be able to lookup using MyEJB?

and here's my lookup code

InitialContext ic;
ic = new InitialContext();
MyRemoteBean remoteBean = 
        (MyRemoteBean ) ic.lookup("java:comp/env/MyEJB");

[EDIT]

I've update the ejb-jar.xml as follows

<enterprise-beans>
    <session>
        <ejb-name>MyEJB</ejb-name>
        <ejb-class>test.ejb.MyBean</ejb-class>
        <ejb-local-ref>
            <ejb-ref-name>MyEJB</ejb-ref-name>
            <ejb-ref-type>Session</ejb-ref-type>
            <local>test.ejb.MyLocalBean</local>
            <ejb-link>MyEJBClient.jar#MyEJB</ejb-link>
        </ejb-local-ref>
    </session>
</enterprise-beans>

I get an error ...

cannot Deploy MyBeanEAR Deployment Error for module: MyBeanEAR: Error occurred during deployment: Exception while deploying the app [MyBeanEAR] : Error: Unresolved : MyEJBClient.jar#MyEJB. Please see server.log for more details.

[\EDIT]

[EDIT]

Hi bkail, let me brake down the problem using the correct names.. Initially, this is what my eclipse-sts IDE created by default

<?xml开发者_StackOverflow社区 version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
  <display-name>BatchOverrideEJB</display-name>
  <ejb-client-jar>BatchOverrideEJBClient.jar</ejb-client-jar>
</ejb-jar>

and this is how i tried accessing the EJB

Properties p = new Properties();
p.put("org.omg.CORBA.ORBInitialHost","localhost");
p.put("org.omg.CORBA.ORBInitialPort","3700");
InitialContext ctx = new InitialContext(p);

ic = new InitialContext(p);

BatchOverrideManagerRemote batchOverrideRemote = 
    (BatchOverrideManagerRemote) ic.lookup("java:comp/env/BatchOverrideEJB");

running this i got the following error

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at za.co.sanlam.batchovveride.test.BatchOverrideTester.main(BatchOverrideTester.java:33)

I thought this error meant that my EJB its not bound to the context, so i modified the ejb-jar.xml as follows

<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:ejb="http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
    <enterprise-beans>
        <session>
            <ejb-name>BatchOverrideEJB</ejb-name>
            <ejb-class>com.test.ejb.BatchOverrideManagerBean</ejb-class>
            <ejb-local-ref>
                <ejb-ref-name>BatchOverrideEJB</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <local>com.test.batchoverridemanager.ejb.BatchOverrideManagerLocal</local>
                <ejb-link>BatchOverrideEJB</ejb-link>
            </ejb-local-ref>
        </session>
    </enterprise-beans>
</ejb-jar

but now i get javax.naming.NameAlreadyBoundException: Use rebind to override [/EDIT]


Try <ejb-link>MyEJB</ejb-link>. That said, test.ejb.MyLocalEJB doesn't sound like a home interface that extends EJBHome, so perhaps you meant to use <business-remote> rather than <remote> and <home>? If you're using a container that supports EJB 3.1, you'll probably find it easier to just use annotations:

@Stateless
public class MyBean implements MyLocal { ... }
@Local
public interface MyLocal { ... }
@Remote
public interface MyRemote { ... }

As an aside MyLocalBean and MyRemoteBean are unusual names for business interfaces. Typically, the Bean suffix is reserved for the EJB class itself.

Edit #2:

For the second edit, see this link:

http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#nonJavaEEwebcontainerRemoteEJB

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜