How to do it...

  1. Start by creating a root for your JAX-RS endpoints:
@ApplicationPath("webresources")public class AppConfig extends Application{}
  1. Create a User class (this will be your MODEL):
public class User {    private String name;    private String email;    public User(String name, String email) {        this.name = name;        this.email = email;    }    //DON'T FORGET THE GETTERS AND SETTERS    //THIS RECIPE WON'T WORK WITHOUT THEM}
  1. Now, create a Session Bean, which will be injected later in your Controller:
@Statelesspublic class UserBean {        public User getUser(){        return new User("Elder", "elder@eldermoraes.com");    }}
  1. Then, create the Controller:
@Controller@Path("userController")public class UserController {        @Inject    Models models;        @Inject UserBean userBean; ...

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.