users@glassfish.java.net

Re: Access EJB 3 Local Interface from servlet

From: Alexis Moussine-Pouchkine <alexis.mp_at_sun.com>
Date: Tue, 18 Aug 2009 15:54:48 +0200

you need to add the appropriate <ejb-local-ref> section in web.xml
-Alexis

On Aug 18, 2009, at 15:30, glassfish_at_javadesktop.org wrote:

> Hello,
>
> I know there's a section in the FAQ concerning this question, but
> I've read it at least 3 times and still don't get my app running.
>
> My problem is that I have a ejb module and a web application module
> packed in an EAR and want my Servlet (in the web app) to access a
> bean (in the ejb module) with its local interface. But always I get
> either an "Invocation exception" or the lookup returns null.
>
> Since both applications are in the same EAR this should be possible,
> I think.
> I'm using Eclipse 3.4, Glassfish 2.1 and JEE5, my code looks like
> this:
>
> @Local
> public interface BeanLocal {
> Week getWeekByDay(Date day);
> }
>
> @Remote
> public interface BeanRemote {
> Week getWeekByDay(Date day);
> }
>
> @Stateless(name="ejb/bean")
> public class Bean implements BeanLocal, BeanRemote { ... }
>
> In the servlet:
> InitialContext ctx = new InitialContext();
> bean = (BeanLocal) ctx.lookup("java:comp/env/ejb/bean");
>
> I've tried dependency injection with @EJB, with mappedName, with
> name and beanInstance, with and without InitialContext, with and
> without java:comp/env, with fully qualified name, with and without
> BeanRemote interface, but nothing seems to work.
>
> When I browse the JNDI tree with GlassFish I only see the Remote
> Interfaces, those I can access with my Servlet, but no Local
> interfaces.
>
> Hope somebody can help me!
> [Message sent by forum member 'encey' (encey)]
>
> http://forums.java.net/jive/thread.jspa?messageID=360950
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>