users@glassfish.java.net

Re: Access EJB 3 Local Interface from servlet

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

Hi,

I'm not really familiar with injection into a servlet, but you should be able to lookup the local interface in the servlet if you add an ejb-local-ref to your web.xml. Please note that the web-app version in the web.xml needs to be at least version 2.3 IIRC. If not even 2.5.

In our web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns="http://java.sun.com/xml/ns/javaee"
                 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                 id="WebApp_ID" version="2.5">

Then, later in the web.xml we have the following:

 <ejb-local-ref>
                <ejb-ref-name>SomeBean</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                <local-home />
                <local>some.package.SomeBeanLocal</local>
</ejb-local-ref>

In the servlet we access it like this:
InitialContext context = new InitialContext();
context.lookup( "java:comp/env/SomeBean");

Hope that helps.
Chris
[Message sent by forum member 'chrjohn' (chrjohn)]

http://forums.java.net/jive/thread.jspa?messageID=360962