我是新來的EJB,並嘗試使用「Hello World」類型的EJB Java程序。這裏是我的EJB:EJB - 查找失敗的'ejb/BookRequestBean'
package dukesbookstore.ejb;
@Stateless(name="BookRequestBean", mappedName="ejb/BookRequestBean")
@Named
public class BookRequestBean {
//Other codes here
}
,這裏是我的客戶:
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
prop.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
prop.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
try {
InitialContext ctx = new InitialContext(prop);
ctx.lookup("ejb/BookRequestBean");
System.out.println("EJB Look-up successfull!!");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但每當我嘗試運行,我得到以下異常:
javax.naming.NamingException中:查找在SerialContext中'ejb/BookRequestBean'失敗[myEnv = {org.omg.CORBA.ORBInitialPort = 3700,java.naming.factory.initial = com.sun.enterprise.naming.SerialInitContextFactory,org.omg.CORBA.ORBInitialHost = localhost,java
我已添加appserv-rt.jar
,gf-client.jar
javaee.jar
,但仍然沒有運氣。任何人都可以幫助我,我在這裏錯過了什麼?我usign Glassfish的3.1
Full stacktrace將有所幫助。確保你也看看這個:http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB – LMeyer 2013-05-10 21:15:37