We used two kinds of injection:
- 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, the @Inject works like the @PostConstruct annotation, with the difference begin in 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) ...