简体   繁体   English

EJB3 bean中的可选注入或运行时依赖性检查

[英]Optional injection in EJB3 bean or runtime dependency checks

I want to define injection so that only if the injected interface has EJB it will be injected. 我想定义注入,这样只有注入的接口有EJB才会注入。 This is used as a plug-in to the main EJB. 这用作主EJB的插件。 How to do this? 这个怎么做? Is there some annotation for this? 这有注释吗?

I can use @PostConstruct to manually "inject" the variable. 我可以使用@PostConstruct手动“注入”变量。 But then I have to handle the dependencies by myself. 但后来我必须自己处理依赖关系。 How can I handle dependencies knowing that one of them is optional? 我怎么能处理依赖关系知道其中一个是可选的? How do I handle the order of deployment of different dependent modules. 如何处理不同依赖模块的部署顺序。

Update: I see that google has an inject annotation with optional parameter: 更新:我看到google有一个带有optional参数的注入注释:

import com.google.inject.Inject;
@Inject(optional = true)

Update 2: JBoss has something that may be what I'm looking for: 更新2: JBoss有可能是我正在寻找的东西:

import org.jboss.annotation.IgnoreDependency;
@IgnoreDependency @EJB OtherBean otherBean;

The solution would be to use JNDI and not injection in this particular case. 解决方案是在这种特殊情况下使用JNDI而不是注入。 That way I have full control over the dependencies. 这样我就可以完全控制依赖关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM