We used two kinds of injections:
- From UserBean, when UserService is attached to the context
- From UserService itself
Injection from UserBean is the simplest possible to perform:
@Inject
private UserBean userBean;
Injection from UserService itself is also simple:
@Inject
private void setUserLocal(){
long ts = System.currentTimeMillis();
userLocal = new User("Local" + ts, "user" + ts +
"@eldermoraes.com");
}
Here, @Inject works like the @PostConstruct annotation, with the server context running the method. But the result is quite the same.
Everything is injected, so now it's just a matter of getting the results:
response = target.path("webresources/userservice/getUserFromBean")
.request()
.accept(MediaType.APPLICATION_JSON)
.get(User.class);
...
response = target.path("webresources/userservice/getUserFromLocal")
.request()
.accept(MediaType.APPLICATION_JSON)
.get(User.class);