On Today at 9:16am, WW=>Wes Wannemacher <w...@wantii.com> wrote:

WW> Sorry Robin, this is on my to-do list, but it's not something I'm
WW> working on right this second. One thing that is holding me up is the
WW> lack of knowledge of JEE. Is there a standard mechanism for creating
WW> instances of EJB-hydrated objects?
WW> 
WW> [..snip..]
WW> 

Hi Wes,

I don't know much of the details about the JEE spec, however, I can share 
my implementation with you. The code is not in production yet, so caveat
emptor (it works for us, for now in development).

I use glassfish as my app server. To expose local EJB interfaces within 
our entire application, I use an EJBInvokerServlet (uses the @EJB and 
@EJBs annotations). The listing is as follows (took out package and import 
statements and anonymized):

    @EJBs(
        value = {
            @EJB(beanInterface = Local1.class, name = "ejb/local1"),
            @EJB(beanInterface = Local2.class, name = "ejb/local2"),
        }
    )
    /**
     * Used to make local interfaces of listed EJBs available within the whole
     * web application.
     */
    public class EJBInvokerServlet extends HttpServlet {
    }

The other way to inject beans is by specifying <ejb-local-ref> inside web.xml.
    <ejb-local-ref>
        <ejb-ref-name>Local1Bean</ejb-ref-name>
        <ejb-ref-type>Session</ejb-ref-type>
        <local>Local1</local>
    </ejb-local-ref>
I prefer the Servlet approach as its simpler.

Wherever we need the EJBs to be automagically injected (the container does 
its part because of EJBInvokerServlet), we then use the @Resource 
annotation, e.g., to inject the Local1 interface, I would use:

    @Resource(mappedName = "ejb/local1")
    private Local1 local1;

Hope that helps.
--
Haroon Rafique
<haroon.rafi...@utoronto.ca>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to