How to do it...

  1. We are going to build a JAX-RS based application, so we will start by preparing the application to perform:
@ApplicationPath("webresources")public class Application extends javax.ws.rs.core.Application {}
  1. Then, we create a User application as our main object:
public class User implements Serializable {    private String name;    private String email;    //DO NOT FORGET TO ADD THE GETTERS AND SETTERS}

Our User class doesn't have a default constructor, so CDI doesn't know how to construct the class when it tries to inject it. So, we create a factory class and use the @Produces annotation over its methods:

public class UserFactory implements Serializable{    @Produces    public User getUser() { return new User("Elder Moraes", "elder@eldermoraes.com"); ...

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.