Reputation: 2894
In terms of objects created at run time by the application server, what is the difference between
making of a bean both an EJB and a JAX-RS resource
@Stateless
@Local
@Path("current")
public class Facade
{
@PersistenceContext
EntityManager entityManager;
@EJB
...
// methods
}
using two different beans
@Path("current")
public class Facade
{
@EJB
private MyEjb myEjb;
// methods
}
@Stateless
@Local
public class MyEJB
{
// methods
}
Thanks for your answers!
EDIT:
ahah maybe my real questions would be about what's the result of using jax-rs annotations on an EJB, but that' basically the same question I asked.
Upvotes: 1
Views: 90
Reputation: 9857
It works. But if we stick to Oracle specification, exposing an EJB as a Web Service (rest or soap) is a kind of quick solution, with you promising to revisit this approach in the nearest future :-)
Infact, again sticking to what Oracle say, the EJB should reside on the business layer, and the web service should be in the integration layer.
I am not arguing that exposing an EJB is a wrong approach, but just because it is quite easy to develop rest service in Java, I would create a façade class, and transform in a service. Then I would inject the EJB into the class, or by jndi lookup if it is a rest. To have better separation of concerns.
This way you don't end up with a single class stuffed with annotation, but you are introducing flexibility, and have an architecture that may evolve, for example maybe you can decide in the future to deploy the business layer on a dedicated machine...whatever.
Upvotes: 2