Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

When to use a CDI producer field or method

DZone's Guide to

When to use a CDI producer field or method

· Java Zone
Free Resource

Just released, a free O’Reilly book on Reactive Microsystems: The Evolution of Microservices at Scale. Brought to you in partnership with Lightbend.

 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

Strategies and techniques for building scalable and resilient microservices to refactor a monolithic application step-by-step, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}