Improving service's capabilities with JAX-RS and CDI
This recipe will show you how to take advantage of CDI and JAX-RS features to reduce the effort and lower the complexity of writing powerful services.
Getting ready
Start by adding the Java EE dependency:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
How to do it...
- We first create a
User
class to be managed through our service:
public class User implements Serializable{ private String name; private String email; public User(){ } public User(String name, String email) { this.name = name; this.email = email; } //DO NOT FORGET TO IMPLEMENT THE GETTERS AND SETTERS }
- To have multiple sources of
User
objects, we create aUserBean
class:
@Stateless...