Optional injection into an EJB3 bean or dependency checking at runtime

I want to define an injection, so only if the injected interface has an EJB will it be injected. It is used as a plugin for core EJB. How to do it? Is there any annotation for this?

I can use @PostConstruct to "inject" the variable manually. But then I have to handle the dependencies myself. How can I handle dependencies knowing that one of them is optional? How to handle the deployment order of various dependent modules.

Update: I see that google has an append annotation with a parameter optional:

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

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

import org.jboss.annotation.IgnoreDependency;
@IgnoreDependency @EJB OtherBean otherBean;
+3
source share
1 answer

The solution would be to use JNDI rather than injection in this particular case. Thus, I have full control over the dependencies.

+1
source

Source: https://habr.com/ru/post/1708968/


All Articles