当前位置: 技术问答>java相关
EJB问题,关于命名环境。
来源: 互联网 发布时间:2015-01-06
本文导语: //get naming context Context ctx = new InitialContext(); //look up jndi name Object ref = ctx.lookup("HelloWorld"); 看到一个EJB的例子;得到命名环境的是上面的两句话; 我想Context ctx = new InitialContext();就是得到了缺省得命名环境...
//get naming context
Context ctx = new InitialContext();
//look up jndi name
Object ref = ctx.lookup("HelloWorld");
看到一个EJB的例子;得到命名环境的是上面的两句话;
我想Context ctx = new InitialContext();就是得到了缺省得命名环境,如果要写全了应该怎样写;
如果当时有两个命名环境,程序如何判断用哪一个。
Context ctx = new InitialContext();
//look up jndi name
Object ref = ctx.lookup("HelloWorld");
看到一个EJB的例子;得到命名环境的是上面的两句话;
我想Context ctx = new InitialContext();就是得到了缺省得命名环境,如果要写全了应该怎样写;
如果当时有两个命名环境,程序如何判断用哪一个。
|
This is a Websphere demo. just for your reference.
// Get the initial context
java.util.Hashtable properties = new java.util.Hashtable(2);
properties.put(javax.naming.Context.PROVIDER_URL, "IIOP://192.168.0.20:900/"); // local name server
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory"); // IBM name services
javax.naming.InitialContext initContext = null;
initContext = new javax.naming.InitialContext(properties);
/*
* Find all Customer Entity Beans which
* match the loginname
*/
CustomerHome customerHome = null;
Object obj = initContext.lookup("cdworld/Customer"); // JNDI name
customerHome = (CustomerHome) javax.rmi.PortableRemoteObject.narrow(obj,CustomerHome.class);
// Get the initial context
java.util.Hashtable properties = new java.util.Hashtable(2);
properties.put(javax.naming.Context.PROVIDER_URL, "IIOP://192.168.0.20:900/"); // local name server
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory"); // IBM name services
javax.naming.InitialContext initContext = null;
initContext = new javax.naming.InitialContext(properties);
/*
* Find all Customer Entity Beans which
* match the loginname
*/
CustomerHome customerHome = null;
Object obj = initContext.lookup("cdworld/Customer"); // JNDI name
customerHome = (CustomerHome) javax.rmi.PortableRemoteObject.narrow(obj,CustomerHome.class);
|
weblogic:
public static Context getWeblogicInitialContext()
throws javax.naming.NamingException {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://bingo:7001");
return new InitialContext(p);
}
public static Context getWeblogicInitialContext()
throws javax.naming.NamingException {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://bingo:7001");
return new InitialContext(p);
}