Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
like image 292
m_vitaly Avatar asked Feb 26 '26 05:02

m_vitaly


1 Answers

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

like image 198
m_vitaly Avatar answered Mar 01 '26 01:03

m_vitaly