- 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 {}
- 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"); ...