How it works...

Well, there's a lot happening in the previous section! We should first have a look at the @Produces annotation. It is a CDI annotation that says to the server: "Hey! This method knows how to construct a User object."

As we didn't create a default constructor for the User class, the getUser method from our factory will be injected into our context as one.

The second annotation is our custom annotation @Profile that has our enumeration ProfileType as a parameter. It is the qualifier of our UserProfile objects.

Now, let's have a look at these declarations:

@Profile(ProfileType.ADMIN)public class ImplAdmin implements UserProfile{   ...}@Profile(ProfileType.OPERATOR)@Defaultpublic class ImplOperator implements UserProfile{   ...}

Get Java EE 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.