Top "Cdi" questions

Contexts and Dependency Injection (CDI): Java Platform, Enterprise Edition (Java EE) 5 brought dependency injection (DI) with Convention over Configuration to Enterprise JavaBeans (EJB) 3.0. Java EE 6 introduces the flexible and powerful @Inject dependency injection model (JSR-330 and JSR-299) in addition to the already existing @EJB annotation.

Understanding cdi Instance<> and .get() vs @Inject

I'm a little confused about which to use in the following situation: Suppose the servlet creates an Application that handles …

jakarta-ee java-ee-6 cdi jboss-weld
Injecting a Spring bean using CDI @Inject

I'm trying to inject a bean defined in a Spring context into a CDI managed component but I'm not successful. …

java spring jsf cdi jboss-weld
How to select a container by qualifyer from arquillian.xml?

I want to have different container configurations in my arquillian.xml and select them in my test. But I am …

java testing jakarta-ee cdi jboss-arquillian
How to create and destroy CDI (Weld) Managed Beans via the BeanManager?

I'm trying to create instances of CDI managed beans using the BeanManager rather than Instance .select().get(). This was suggested …

java garbage-collection cdi managed-bean jboss-weld
Inject list of objects in CDI (Weld)

Let's say I have an interface called SocialNetworkService, and three implementations - TwitterService, FacebookService and FriendFeedService. Now I want, whenever …

java cdi jboss-weld
How to inject an interface implementation?

I have the following interface public interface IMyMapper<T> {} and the implementation public class MyMapper implements IMyMapper<…

java jakarta-ee cdi java-ee-7
Why use constructor over setter injection in CDI?

I couldn't find any reasonable answer here on SO so I hope it's not a duplicate. So why should I …

java dependency-injection cdi
Constructor injection vs Field injection

When injecting any services, I have two choices : Field injection: @Inject private MyService myService; or Constructor injection: private MyService myService; @…

java dependency-injection sonarqube cdi
CDI Ambiguous dependency with @Produces - why?

I am using code like below: public Configuration { private boolean isBatmanCar = someMethod(...); @Produces public Car getCar(@New Car car) { if(…

jakarta-ee cdi weld
How to inject mocks while testing classes using CDI in production

I am programming in a Java SE environment using WELD-SE for dependency injection. Therefore dependencies of a class look something …

java unit-testing mockito cdi