首先:websphere server处于启动状态,jndi已在服务器下配置,名称为
mail/wfewcs/wfewcs_mailservice
1.在需要脱离container(app未部署至websphere)进行JNDI lookup查找时,
可以使用如下代码(以mail session的jndi为例):
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
properties.put(Context.PROVIDER_URL, "iiop://localhost:2809/");
Context ctx=new InitialContext(properties);
Session
mail_session= (Session)ctx.lookup("mail/wfewcs/wfewcs_mailservice");
JAR要求:wssec.jar, naming.jar, namingclient.jar,
sas.jar and ecutils.jar,如果IDE为IBM RAD,则只需添加websphere运行时库以及namingclient.jar包即可(此jar不在websphere运行时库中)。
2.在container中(app已部署至websphere)进行jndi lookup查找:
比较简单:
Context ctx=new InitialContext();
Session mail_session= (Session)ctx.lookup("mail/wfewcs/wfewcs_mailservice");