@EJBs注释是做什么的? [英] What does the @EJBs annotation do?
问题描述
@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
等)有两个目的:
- 它在组件命名空间中声明一个引用。例如,
@EJB(name =myEJB)
创建一个引用java:comp / env / myEJB
。如果您注释一个字段并且不指定名称,那么它将创建一个引用java:comp / env / com.example.MyClass / myField
。 - 如果在字段或setter方法上声明注释,则在创建组件时容器执行注入。
引用的解决方式有所不同,不管是否为查找(java:comp / env / myEJB)
或由于注入而解析引用:
- 如果使用EE 6+,
查找
属性需要一个JNDI查找来解决目标。 - 某些应用服务器支持
mappedName
,它被指定为供应商特定的。这通常通过执行查找来实现。 - 应用程序服务器在部署时支持绑定。这通常通过执行查找来实现。
- 如果没有提供其他绑定信息,并且bean接口(
beanInterface
或字段类型)仅由应用程序中的单个EJB实现,那么EJB规范要求它回退到。 - 如果没有提供其他绑定信息,#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:
- It declares a reference in the component namespace. For example,
@EJB(name="myEJB")
creates a referencejava:comp/env/myEJB
. If you annotate a field and do not specify a name, then it creates a referencejava:comp/env/com.example.MyClass/myField
. - 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:
- If EE 6+ is used, the
lookup
attribute requires a JNDI lookup to resolve the target. - Some application servers support
mappedName
, which is specified to be vendor specific. This is usually implemented by performing a lookup. - Application servers support bindings at deployment time. This is usually implemented by performing a lookup.
- 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. - 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 ofmyEJB
in the server namespace).
这篇关于@EJBs注释是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!