
上QQ阅读APP看书,第一时间看更新
Producer methods and fields
A producer method or field is a method or field of a bean class annotated as @Produces. It generates beans after the deployment time of the application hosting the CDI engine.
Here's a sample producer method:
@Published
@Produces
public List<Book> getPublishedBooks() {
Book[] books = new Book[] { new Book("Mastering Java EE Development with WildFly 10", "Luca Stancapiano", PUBLISHED),
new Book("Gatein Cookbook", "Luca Stancapiano", PUBLISHED) };
return asList(books);
}
We have a @Published qualifier used to identify the list of books and the @Produces annotation. Thanks to this last annotation, we can inject a list of books from a bean and it will be automatically populated with the books:
@Inject
@Published
private List<Book> publishedBooks;