- Start by creating a root for your JAX-RS endpoints:
@ApplicationPath("webresources")public class AppConfig extends Application{}
- 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}
- 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"); }}
- Then, create the Controller:
@Controller@Path("userController")public class UserController { @Inject Models models; @Inject UserBean userBean; ...