I read a lot on this topic on SO and the web but there seem to be problems when dealing with older posts...
I want to expose my EJB business logic to a rest api / inject an ejb into a jersey resource.
Using @EJB works fine but there are people out there suggesting not to use @EJB for local beans.
There are different methods to inject beans in services with @Inject. The easiest (to me) seems to be the following:
@RequestScoped // This line is important!
@Path("service")
public class Rest {
@Inject Bean beany;
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get () {
return beany.saySomething();
}
}
Annotating the resource as cdi does the job.
This discussion brought me to the solution but also states problems (behaviour not specified). I would like to know if the situation is clearer by now.
I'm using the libraries shipped with glassfish 4.
Is there a JEE-7-best-practice-way to achieve this? It's really hard to dig through outdated discussions.
Thanks in advance!