@EJBs注释是做什么的? [英] What does the @EJBs annotation do?

查看:137
本文介绍了@EJBs注释是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大概知道这个结构的作用:它创建一个SomeType EJB,并将objecty注入另一个EJB。

  @EJB (name =name1)
SomeType someVariable

现在我有一个类开始像(我给所有类级别的注释,甚至很难我认为只有 @EJBs 是相关的)

  @Remote(SomeClass.class)
@Stateless(name =someName)
@EJBs({@ EJB(name =name1,beanInterface = Type1。类)
@EJB(name =name2,beanInterface = Type2.class)})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class X extends Y {
// code

@EJB 在这里做?他们可能从JNDI获取或创建name1...对象,但是他们在哪里放置结果?我没有在附近看到一个 .lookup 通话,但代码库很大,所以我不太确定。



奖金问题:我假设2个交易注释只是重复默认值?



更新: code> @EJBs 是专有的扩展。不是这样。它是Java EE5的核心部分。有关详细信息,请参阅 JavaDoc。它只是个人 @EJB 注释的容器。



我相信每个声称这些EJB注释的人都会抬头。我只是想知道这个查找结果会发生什么。

解决方案

@EJB 注释(和 @Resource @WebServiceRef 等)有两个目的:


  1. 它在组件命名空间中声明一个引用。例如, @EJB(name =myEJB)创建一个引用 java:comp / env / myEJB 。如果您注释一个字段并且不指定名称,那么它将创建一个引用 java:comp / env / com.example.MyClass / myField

  2. 如果在字段或setter方法上声明注释,则在创建组件时容器执行注入。

引用的解决方式有所不同,不管是否为查找(java:comp / env / myEJB)或由于注入而解析引用:


  1. 如果使用EE 6+,查找属性需要一个JNDI查找来解决目标。

  2. 某些应用服务器支持 mappedName ,它被指定为供应商特定的。这通常通过执行查找来实现。

  3. 应用程序服务器在部署时支持绑定。这通常通过执行查找来实现。

  4. 如果没有提供其他绑定信息,并且bean接口( beanInterface 或字段类型)仅由应用程序中的单个EJB实现,那么EJB规范要求它回退到。

  5. 如果没有提供其他绑定信息,#4无法工作,某些应用程序服务器将尝试根据ref名称在服务器命名空间中执行查找(例如, java:comp / env / myEJB 可能会导致查找 myEJB 在服务器命名空间中)。


I know roughly what this construction does: It creates a SomeType EJB and injects the objecty into another EJB.

 @EJB(name="name1")
 SomeType someVariable

Now I have a class which starts like this: (I give all class-level annotations, even tough I think only the @EJBs is relevant)

@Remote(SomeClass.class)
@Stateless(name="someName")
@EJBs({@EJB(name="name1",beanInterface=Type1.class),
       @EJB(name="name2",beanInterface=Type2.class)})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class X extends Y{ 
  //code

What do the @EJB's do here? They probably get or create the "name1" ... objects from JNDI, but where do they put the result? I don't see a .lookup call anywhere near, but the codebase is huge so I'm not very sure about this.

Bonus question: I presume the 2 transaction annotations simply repeat defaults?

UPDATE: Multiple persons claimed at this point that @EJBs is a proprietary extension. It is not. It is a core part of java EE5. See the JavaDoc for details.. It is simply a container for the individual @EJB annotations.

I believe everyone who claims these EJB annotations do a lookup. I just want to know what happens with the result of this lookup.

解决方案

The @EJB annotation (and @Resource, @WebServiceRef, etc.) serves two purposes:

  1. It declares a reference in the component namespace. For example, @EJB(name="myEJB") creates a reference java:comp/env/myEJB. If you annotate a field and do not specify a name, then it creates a reference java:comp/env/com.example.MyClass/myField.
  2. If the annotation is declared on a field or setter method, then the container performs injection when the component is created.

How the reference is resolved varies, independent of whether the reference is being resolved for a lookup("java:comp/env/myEJB") or due to injection:

  1. If EE 6+ is used, the lookup attribute requires a JNDI lookup to resolve the target.
  2. Some application servers support mappedName, which is specified to be vendor specific. This is usually implemented by performing a lookup.
  3. Application servers support bindings at deployment time. This is usually implemented by performing a lookup.
  4. If no other binding information is provided and the bean interface (beanInterface or the field type) is only implemented by a single EJB in the application, then the EJB specification requires that it fall back to that.
  5. If no other binding information is provided and #4 cannot work, some application servers will attempt to perform a lookup in the server namespace based on the ref name (for example, java:comp/env/myEJB might cause a lookup of myEJB in the server namespace).

这篇关于@EJBs注释是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆