-
@Target(value={METHOD,FIELD}) @Retention(value=RUNTIME) @Documented public @interface Produces
Identifies a producer method or field. May be applied to a method or field of a bean class.
A producer method must be a non-abstract method of a managed bean class or session bean class. A producer method may be either static or non-static. If the bean is a session bean, the producer method must be either a business method of the EJB or a static method of the bean class.
public class Shop { @Produces @ApplicationScoped @Catalog @Named("catalog") List<Product> getProducts() { ... } ... }
A producer field must be a field of a managed bean class or session bean class. A producer field may be either static or non-static. If the bean is a session bean, the producer field must be a static field of the bean class.
public class Shop { @Produces @ApplicationScoped @Catalog @Named("catalog") List<Product> products = ...; ... }
If a producer method sometimes returns a null value, or if a producer field sometimes contains a null value when accessed, then the producer method or field must have scope
@Dependent
.A producer method return type or producer field type may not be a type variable.
If the producer method return type or producer field type is a parameterized type, it must specify an actual type parameter or type variable for each type parameter.
If the producer method return type or producer field type is a parameterized type with a type variable, it must have scope
@Dependent
.A producer method may have any number of parameters. All producer method parameters are injection points.
public class OrderFactory { @Produces @ConversationScoped public Order createCurrentOrder(Shop shop, @Selected Product product) { Order order = new Order(product, shop); return order; } }
A bean may declare multiple producer methods or fields.
Producer methods and fields are not inherited by bean subclasses.
Interceptors and decorators may not declare producer methods or fields.
- Author:
- Gavin King, Pete Muir
- See Also:
@Disposes
Document created the 11/06/2005, last modified the 18/08/2025
Source of the printed document:https://www.gaudry.be/en/java-api-javaee-rf-javax/enterprise/inject/produces.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author of this site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.