【发布时间】:2015-08-12 12:26:32
【问题描述】:
我是 EJB 概念的新手。我在不同的网站上看到了以下内容:
样本 1:
@Stateless
@EJB(name="audit", beanInterface=AnotherEJBLocal.class)
public class EmployeeBean implements EmployeeServiceLocal, EmployeeServiceRemote {
@PersistenceContext(unitName = "EmployeeService")
private EntityManager manager;
public void doAction(){
try {
Context ctx = new InitialContext();
AnotherEJBLocal audit = (AnotherEJBLocal) ctx.lookup("java:comp/env/audit");
audit.doAnother();
} catch (NamingException e) {
throw new EJBException(e);
}
}
}
示例 2:
public static void main(String[] a) throws Exception {
EmployeeServiceRemote service = null;
service = (EmployeeServiceRemote) new InitialContext().lookup("EmployeeBean/remote");
service.doAction();
}
示例 3:
obj = ctx.lookup(ejb/CBDWebAppEAR/CBDWebApp.jar/<EJB name>/<Remote Interface Class Name>);
CBDWebApp 是 bean 所在的项目名称。
我的问题是:
java:comp/env/audit 的需要和意义是什么
为什么在示例 2 的情况下不使用相同类型的字符串。我猜是 它是一个非本地的远程 EJB。
示例3中EJB查找字符串的含义是什么。
【问题讨论】:
标签: ejb ejb-3.0 jndi ejb-3.1 ejb-2.x