Announcement Announcement Module
Collapse
No announcement yet.
Local EJB interface and component initialized by spring IoC container Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Local EJB interface and component initialized by spring IoC container

    Hi,

    It may be strange question, but I am spring newbie and this one thing is unclear for me.

    As I've read here:
    http://static.springsource.org/sprin.../html/ejb.html
    I can access Remote and Local interfaces of EJBs deployed on some application server.
    Obtaining remote reference is pretty clear for me - we have spring client using beans initialized by spring context.xml and those beans, which need to have reference to remote EJBs interfaces, are obtaining it through JNDI. Something like below (our thin spring client residing on local machine, obtaining EJB's remote interfaces through jndi):

    OurSpringApp (on our machine) <--JNDI--> (Remote)MyBean (on application server)

    Ok, but the point about obtaining Local EJB interface is not so clear for me. As the local interface in EJB3 I mean:

    Code:
    @Local
    MyLocalInterface {
      void someMethod();
    }
    
    @Stateless
    MyStatelessBean implements MyLocalInterface {
      @Override
      void someMethod() { /* nothing */ }
    }
    and MyLocalInterface can be used only by components (beans) residing on the same application server as instance of MyStatelessBean. So My Spring application also have to be deployed there.

    Ok, I can pack it into jar/war and deploy it, but how then can I obtain reference to those deployed spring beans from my local thin client? How should I initialize spring beans factory on application server? Could you please give me some simple example?

    Thank you in advance!
    Last edited by PiotrD; Aug 12th, 2010, 10:50 AM.

  • #2
    There is no difference, you still do the jndi lookup and inject it.

    Also it has nothing to do with the same application server but the same VM, you can have 2 applications however if app 1 want to use an ejb from app 2 it still is a remote ejb and not a local one!.

    If you only want to use EJB (and don't have a web client) use a BeanFactoryLocator (also explained in the EJB chapter of the reference guide) to load the applicationcontext. If you have a war, use a ContextLoaderListener.

    Comment


    • #3
      Thank you for your response, it is much more clear for me now, but I still have some questions

      I am wondering about design of such a "ejb-spring integrated application". How it should look like from application server and client sites?
      Probably the most common situation is when we have some part of application written in EJB already and now we want to implement (no matter why) the other part of app in Spring.

      So is it the correct way of implementation?
      Client has it's own application context, it's doing jndi lookop for beans allocated on server and injecting them. The client (by JNDI) is referencing to JavaEJBs serving as a facade (it could be servlet as well). This facade is loading spring context located on application server and (by doing it) initializing Spring beans declared in application context. All other spring beans, if they need reference to context - they obtain it by BeanFactoryLocator (we want to have only one instance of context).
      Anyway, all communication between client and server is done by obtaining JNDI to Java EJB (or Spring EJB - classes extending AbstractStatelessSessionBean, AbstractStatefulSessionBean and so on) or by Java servlet which is responsible for loading spring context.

      Comment

      Working...
      X