Platinum Partner
java

When to use a CDI producer field or method

 Conforming to the official specification, a producer field can be used:

• instead of a simple getter method
• for declaring Java EE resources

Moreover, a producer method can be used – producer methods acts as sources of bean instances:

• to inject non-beans objects (expose any JDK class as a bean)
• to inject objects that have type that vary at runtime (vary the implementation of a bean type at runtime)
• to inject objects that requires some custom initialization that the bean constructor does not perform (define multiple beans, with different scopes or initialization, for the same implementation class).

From http://e-blog-java.blogspot.com/2011/04/when-to-use-cdi-producer-field-or.html

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}