m_vitaly
m_vitaly

Reputation: 11952

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. This is used as a plug-in to the main EJB. How to do this? Is there some annotation for this?

I can use @PostConstruct to manually "inject" the variable. 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:

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

Update 2: JBoss has something that may be what I'm looking for:

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

Upvotes: 3

Views: 2282

Answers (1)

m_vitaly
m_vitaly

Reputation: 11952

The solution would be to use JNDI and not injection in this particular case. That way I have full control over the dependencies.

Upvotes: 1

Related Questions