0

Q1) It is mentioned in the JavEE 7 tutorial that CDI injections can happen only in container manager objects such as servlets, EJB's and managed bean. Does it mean that I cannot do CDI injection in a JAX-RS?

Q2) I remember reading in some blog (dont know exactly which one) that with Java EE 7 any POJO objects can be injected anywhere within the container, since the container will "look" for them and initialize. Is that true?

Q3)

To inject an EJB into another bean, one would do

public class MainBean {

@EJB
UserDao userDao;

}

If I have the following POJO's objects

@ThirteenDigits
public class Thirteendigitgenerator implements NumberGenerator { ...}


@FourDigits
public class FourDigitsgenerator implements NumberGenerator { ... }

I ignored the Qualifiers for @ThirteenDigits and @FourDigits here.

If I want to inject above ThirteenDigit POJO into a bean, I would do

@Inject @ThirteenDigits
NumberGenerator numbergenerator;

I am wondering if it is possible to do the following:

@ThirteenDigits
NumberGenerator numbergenerator;
brain storm
  • 30,124
  • 69
  • 225
  • 393
  • 1
    Why are you wanting to avoid the annotation? And other containers, such as Spring, support `@Inject`; the warning is simply that you need machinery to interpret the annotation, and it's not magic. – chrylis -cautiouslyoptimistic- Oct 23 '14 at 23:45
  • @chrylis: I agree with you. but I would like to know if it is possible.. – brain storm Oct 23 '14 at 23:46
  • It's hard to tell what you're asking about. Can you give a more specific example about these "floating objects"? – chrylis -cautiouslyoptimistic- Oct 23 '14 at 23:54
  • I want to know if it is possible to do injection without "@inject" for a POJO, like the example I gave above. plus thoughts on the bottom part of the question – brain storm Oct 24 '14 at 00:30
  • You could probably try to use beanManager api instead of annotations. Check this maybe it will be what you are looking for http://stackoverflow.com/questions/8420070/how-to-create-and-destroy-cdi-weld-managed-beans-via-the-beanmanager – Gas Oct 24 '14 at 01:07

0 Answers0