调用ejb时,如果客户端和ejb不在同一个jvm,就要设置InitialContext,不同的应用服务器InitialContext写法也不同.
Context.INITIAL_CONTEXT_FACTORY:指定到目录服务的连接工厂
Context.PROVIDER_URL:目录服务提供者URL
//jboss:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"
Context.URL_PKG_PREFIXES, "org.jboss.naming"
Context.PROVIDER_URL, "localhost:1099"
Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"
Context.URL_PKG_PREFIXES, "org.jboss.naming"
Context.PROVIDER_URL, "localhost:1099"
//weblogic:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"
Context.PROVIDER_URL, "t3://localhost:7001"
Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"
Context.PROVIDER_URL, "t3://localhost:7001"
//apusic(金蝶):
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.apusic.jndi.InitialContextFactory"
Context.PROVIDER_URL, "rmi://localhost:6888"
Context.INITIAL_CONTEXT_FACTORY, "com.apusic.jndi.InitialContextFactory"
Context.PROVIDER_URL, "rmi://localhost:6888"
//WebSphere:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:900"
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:900"
//J2EE SDK(J2EE RI):
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"
Context.PROVIDER_URL, "iiop://127.0.0.1:1050"
Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"
Context.PROVIDER_URL, "iiop://127.0.0.1:1050"
//SilverStream:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.sssw.rt.jndi.AgInitCtxFactory"
Context.PROVIDER_URL, "sssw://localhost:80"
Context.INITIAL_CONTEXT_FACTORY, "com.sssw.rt.jndi.AgInitCtxFactory"
Context.PROVIDER_URL, "sssw://localhost:80"
//OC4J:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory"
Context.PROVIDER_URL, "ormi://127.0.0.1/"
Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory"
Context.PROVIDER_URL, "ormi://127.0.0.1/"
//WAS5:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:2809"
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:2809"
Borland Enterprise Server JNDI用法
Java代码
Properties props=new Properties();
props.put(Context.PROVIDER_URL,"corbaloc::173.6.7.143:14500/NameService");
props.put("java.naming.factory.initial","com.inprise.j2ee.jndi.CtxFactory");
Context context = new InitialContext(props);
// Context context = new InitialContext();
Object ref = context.lookup("com/borland/examples/j2ee/hello/Hello");
HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow(ref, HelloWorldHome.class);
hello = home.create();
Properties props=new Properties();
props.put(Context.PROVIDER_URL,"corbaloc::173.6.7.143:14500/NameService");
props.put("java.naming.factory.initial","com.inprise.j2ee.jndi.CtxFactory");
Context context = new InitialContext(props);
// Context context = new InitialContext();
Object ref = context.lookup("com/borland/examples/j2ee/hello/Hello");
HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow(ref, HelloWorldHome.class);
hello = home.create();
常用JNDI服务提供者连接工厂:
Filesystem: Com.sun.jndi.fscontext.FSContextFactory或者com.sun.jndi.fscontext.RefFSContextFactory
LDAPv3: Com.sun.jndi.ldap.LdapCtxFactory
NDS: com.novell.naming.service.nds.NdsInitialContextFactory
NIS: com.sun.jndi.nis.NISCtxFactory
RMI registry: com.sun.jndi.rmi.registry.RegistryContextFactory
IBM LDAP服务提供者: com.ibm.jndi.LDAPCtxFactory
BEA 名字服务提供者: weblogic.jndi.WLInitialContextFactory
JBOSS名字服务提供者: org.jnp.interfaces.NamingContextFactory
[url]http://flytosea.iteye.com/blog/374633[/url]
Context.INITIAL_CONTEXT_FACTORY:指定到目录服务的连接工厂
Context.PROVIDER_URL:目录服务提供者URL
//jboss:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"
Context.URL_PKG_PREFIXES, "org.jboss.naming"
Context.PROVIDER_URL, "localhost:1099"
Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"
Context.URL_PKG_PREFIXES, "org.jboss.naming"
Context.PROVIDER_URL, "localhost:1099"
//weblogic:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"
Context.PROVIDER_URL, "t3://localhost:7001"
Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"
Context.PROVIDER_URL, "t3://localhost:7001"
//apusic(金蝶):
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.apusic.jndi.InitialContextFactory"
Context.PROVIDER_URL, "rmi://localhost:6888"
Context.INITIAL_CONTEXT_FACTORY, "com.apusic.jndi.InitialContextFactory"
Context.PROVIDER_URL, "rmi://localhost:6888"
//WebSphere:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:900"
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:900"
//J2EE SDK(J2EE RI):
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"
Context.PROVIDER_URL, "iiop://127.0.0.1:1050"
Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"
Context.PROVIDER_URL, "iiop://127.0.0.1:1050"
//SilverStream:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.sssw.rt.jndi.AgInitCtxFactory"
Context.PROVIDER_URL, "sssw://localhost:80"
Context.INITIAL_CONTEXT_FACTORY, "com.sssw.rt.jndi.AgInitCtxFactory"
Context.PROVIDER_URL, "sssw://localhost:80"
//OC4J:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory"
Context.PROVIDER_URL, "ormi://127.0.0.1/"
Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory"
Context.PROVIDER_URL, "ormi://127.0.0.1/"
//WAS5:
Java代码
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:2809"
Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
Context.PROVIDER_URL, "iiop://localhost:2809"
Borland Enterprise Server JNDI用法
Java代码
Properties props=new Properties();
props.put(Context.PROVIDER_URL,"corbaloc::173.6.7.143:14500/NameService");
props.put("java.naming.factory.initial","com.inprise.j2ee.jndi.CtxFactory");
Context context = new InitialContext(props);
// Context context = new InitialContext();
Object ref = context.lookup("com/borland/examples/j2ee/hello/Hello");
HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow(ref, HelloWorldHome.class);
hello = home.create();
Properties props=new Properties();
props.put(Context.PROVIDER_URL,"corbaloc::173.6.7.143:14500/NameService");
props.put("java.naming.factory.initial","com.inprise.j2ee.jndi.CtxFactory");
Context context = new InitialContext(props);
// Context context = new InitialContext();
Object ref = context.lookup("com/borland/examples/j2ee/hello/Hello");
HelloWorldHome home = (HelloWorldHome) javax.rmi.PortableRemoteObject.narrow(ref, HelloWorldHome.class);
hello = home.create();
常用JNDI服务提供者连接工厂:
Filesystem: Com.sun.jndi.fscontext.FSContextFactory或者com.sun.jndi.fscontext.RefFSContextFactory
LDAPv3: Com.sun.jndi.ldap.LdapCtxFactory
NDS: com.novell.naming.service.nds.NdsInitialContextFactory
NIS: com.sun.jndi.nis.NISCtxFactory
RMI registry: com.sun.jndi.rmi.registry.RegistryContextFactory
IBM LDAP服务提供者: com.ibm.jndi.LDAPCtxFactory
BEA 名字服务提供者: weblogic.jndi.WLInitialContextFactory
JBOSS名字服务提供者: org.jnp.interfaces.NamingContextFactory
[url]http://flytosea.iteye.com/blog/374633[/url]