Building reactive applications using events and observers
Events and observers are a great way to write code in a reactive way without thinking too much about it, thanks to the great work done by the CDI specification.
This recipe will show you how easy is to use it to improve the user experience of your application.
Getting ready
Let's first add our Java EE 8 dependency:
<dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>8.0</version> <scope>provided</scope> </dependency>
How to do it...
- Let's first create a
User
POJO:
public class User implements Serializable{ private Long id; private String name; public User(long id, String name){ this.id = id; this.name = name; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; ...