Friday, August 31, 2007

EJB3 local bean access in servlet using glassfish

I was trying out Glassfish.

I made a separate ear with a stateless bean and a war with a servlet that accesses the stateless bean using @EJB injection. I deployed the ejb jar file and also the servlet war file. It did not work. The error was that the servlet did not find the ejb.

Reading the glassfish docs I came across this question in the glassfish faq.

--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------

Question: I have an EJB with a Local interface. Can I access it from a web component in a different application?

Answer: No, not in our implementation. The EJB spec only requires local ejb access from within the same application in the same JVM.

--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------

Actually that makes a lot of sense.

All I needed to do was to have an ear file with both the war and ear as modules. That way the local EJB could be found by the servlet.

Since the servlet needed to access the local interface I also packaged the interface in WEB-INF/lib/ejbinterfaces.jar folder.

1 Comments:

Blogger Bernd said...

I would prefer to see web apps developed, tested and deployed separate from e.g. business beans in their own EJB modules. And it should always be an option to use local interfaces to facade session beans. Especially when I want to access JPA Entites by reference and not detached.

12:44 PM  

Post a Comment

<< Home