PetStore中的用法实际上等同于配置context-param;并非你想象的这么复杂。
是通过web.xml中配置的env-entry作为索引标志,来取得实际相要得到的类的实例而已。
正确做法:
1. web.xml中的写法不变;
2. 引用中:
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
InitialContext ic = new InitialContext(p);
String className = (String)ic.lookup("JNDITst");
JNDITst t = (JNDITst)ic.lookup(className);
t.PrintHello();