Dependency injection EJB依赖项查找

Dependency injection EJB依赖项查找,dependency-injection,ejb-3.0,Dependency Injection,Ejb 3.0,我正在读一本关于EJB的书,我不理解下一个例子: @Stateless @EJB(name="audit", beanInterface=AuditService.class) public class DeptServiceBean implements DeptService { SessionContext context; AuditService audit; public void setSessionContext(SessionContext cont

我正在读一本关于EJB的书,我不理解下一个例子:

@Stateless
@EJB(name="audit", beanInterface=AuditService.class)    
public class DeptServiceBean implements DeptService {
   SessionContext context;
   AuditService audit;

   public void setSessionContext(SessionContext context) {
     this.context = context;
   }

   @PostConstruct
   public void init() {
     audit = (AuditService) context.lookup("audit");
   }
   // ...
}
本例试图解释“依赖项查找”。我不明白的是,为什么在使用@EJB注释时需要调用查找方法。那么,@EJB注释的用途是什么

我希望@EJB注释足以获得AuditService EJB的实例


谢谢

读了多一点之后,我明白了。前面的示例显示了“依赖项查找”(注释用于类级别)。另一方面,存在“依赖注入”(注释位于字段级别),在这种情况下,@EJB注释就足够了