Search code examples
cdi

What is the correct annotation for a java class to be injectable?


I have a POJO which I want to inject into a CDI Bean. Now I get that I could change the discovery mode in beans.xml from 'annotated' to 'all'. But I also could just give my POJO a bean defining annotation. I guess any annotation would work, but I was wondering, what is the correct annotation just for the single purpose to make my POJO injectable?


Solution

  • @Dependent will create a new instance for that bean on every injection point. Usually the least intrusive.

    http://docs.oracle.com/javaee/7/api/javax/enterprise/context/Dependent.html