users@glassfish.java.net

Access EJB 3 Local Interface from servlet

From: <glassfish_at_javadesktop.org>
Date: Tue, 18 Aug 2009 06:30:20 PDT

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