(1) 通过设置@Stateful or @Stateless annotations的 mappedName 属性,可以取得和在 weblogic-ejb-jar.xml中设置jndi名字一样的效果 。
(2) 此时每个需要绑定到JNDI上的business接口对象的JNDI名字是<mappedName>#<fully qualified interface name>
例如:
@Stateless(name="HelloWorld", mappedName="HelloBean")
@Remote(ejbremotetoi.HelloWorldRemoteManager.class)
public class HelloWorldRemoteBean implements HelloWorldRemoteManager{…}
(3) 对于每个引用者(依赖注入引用)而言,需要如下定义EJB引用:
@EJB(name="HelloWorld", mappedName="HelloBean")
HelloWorldRemoteManager helloWorld;
(4) JNDI 引用:
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
try {
ctx = new InitialContext(ht);
Hello hello = (Hello)ctx.lookup("
HelloBean#
HelloWorldRemoteManager");