日期:2014-05-19 浏览次数:20772 次
Context ctx = new InitialContext(); Object o = ctx.lookup("ejb/TestLocal"); ……
<ejb-local-ref> <ejb-ref-name>ejb/TestLocal</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>com.jeff.TestLocalHome</local-home> <local>com.jeff.TestLocal</local> <ejb-link>TestLocalEJB.jar#TestLocal</ejb-link> </ejb-local-ref>
package com.jeff; import javax.ejb.CreateException; import javax.ejb.EJBLocalHome; public interface TestLocalHome extends EJBLocalHome { public TestLocal create() throws CreateException; }
package com.jeff; import javax.ejb.EJBLocalObject; public interface TestLocal extends EJBLocalObject { public int get6(); }
package com.jeff; import java.rmi.RemoteException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; public class TestBean implements SessionBean { public TestBean() { } public void ejbActivate() throws EJBException, RemoteException { } public void ejbPassivate() throws EJBException, RemoteException { } public void ejbRemove() throws EJBException, RemoteException { } public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException { } //business methods; public int get6() { return 6; } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBean