Platinum Partner

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).


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

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

{{ parent.tldr }}

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

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

{{ parent.views }} ViewsClicks